我想知道如何使用带有Flask的Python获取POST/GET请求变量的值.
使用Ruby,我会做这样的事情:
variable_name = params["FormFieldValue"]
Run Code Online (Sandbox Code Playgroud)
我如何使用Flask做到这一点?
n00b问题.我正在尝试遍历我的数据库中的每个用户记录.伪代码可能看起来像这样:
def send_notifications
render :nothing => true
# Randomly select Message record from DB
@message = Message.offset(rand(Message.count)).first
random_message = @message.content
@user = User.all.entries.each do
@user = User.find(:id)
number_to_text = ""
@user.number = number_to_text #number is a User's phone number
puts @user.number
end
end
Run Code Online (Sandbox Code Playgroud)
有人可以填写我这样做的最佳方法吗?对语法的一点帮助也很棒:)
我正在尝试执行以下向上迁移以更改"tweet"模型表中的"number"列
class ChangeDataTypeForTweetsNumber < ActiveRecord::Migration
def up
change_column :tweets do |t|
t.change :number, :integer
end
end
def down
change_table :tweets do |t|
t.change :number, :string
end
end
end
Run Code Online (Sandbox Code Playgroud)
执行以下向上迁移到heroku ....
heroku rake db:migrate:up VERSION=20120925211232
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
PG::Error: ERROR: column "number" cannot be cast to type integer
: ALTER TABLE "tweets" ALTER COLUMN "number" TYPE integer
Run Code Online (Sandbox Code Playgroud)
任何想法都会非常感激.
感谢大家.
我正在尝试使用"puts"来测试一些在Heroku上托管的Sinatra应用程序.有趣的是,输出似乎排队并且仅在重新启动Heroku dyno时显示.我试过'Thin'和'Webrick',但也有同样的问题.
有什么想法吗?
我正在为顾问建立一个小型短信服务.他希望他的客户能够将短信发送到一个Twilio号码,并将他们转发到他自己的电话号码.当他做出回应时,他希望响应看起来来自Twilio号码(以便隐藏他的个人号码),并最终通过代表SMS通信的单个Twilio号码保持多个对话.我想我可以使用会话来做到这一点,但我不完全确定如何实现它?
对好方法的任何想法?
我与我合作的人分享了一个回购,我只是想让我的开发环境正常运行.其中一个迁移有一个json
属性,我们正在使用Postgres进行开发和生产:
class CreateExams < ActiveRecord::Migration
def change
create_table :exams do |t|
t.belongs_to :user
t.json :exam
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
development:
adapter: postgresql
database: examgen_development
host: localhost
Run Code Online (Sandbox Code Playgroud)
当我运行时rake db:migrate
,我收到一个错误,导致我认为PG不支持JSON列类型:
PG::Error: ERROR: type "json" does not exist
Run Code Online (Sandbox Code Playgroud)
但我知道Postgres 9.2支持JSON(即http://www.postgresql.org/docs/devel/static/datatype-json.html).
有趣的是,当我检查我使用'psql'的PG版本时,它显示9.0.4.而当我使用'postgres'时,它显示9.2.1.所以我不确定我正在使用什么版本以及如何来回切换.
psql --version
psql (PostgreSQL) 9.0.4
postgres --version
postgres (PostgreSQL) 9.2.1
Run Code Online (Sandbox Code Playgroud)
有没有人想到为什么我得到Postgres错误?
我有一个Heroku预定的工作,应该每10分钟运行一次.它只是向控制器的动作发出一个HTTP GET请求.
desc "This task is called by the Heroku scheduler add-on"
task :send_notifications => :environment do
response = HTTParty.get('http://sendnotificationapp.com/sms/send_notifications')
end
Run Code Online (Sandbox Code Playgroud)
当我做一个耙子时,任务运行并正常运行:
heroku rake send_notifications
Run Code Online (Sandbox Code Playgroud)
虽然当我使用Heroku调度程序GUI将其设置为每10分钟运行一次时,它不会运行.相反,我收到以下错误:
Starting process with command `send_notifications` by scheduler@addons.heroku.com
Starting process with command `send_notifications`
bash: send_notifications: command not found
Process exited with status 127
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
谢谢!
我遇到了Clockwork调度程序进程的语法问题.我实际上遇到的问题与此线程中讨论的内容类似,但从未完全回答(如何使用Rails发条工具来运行rake任务?)
当我使用'heroku rake send_notifications'测试时,我的'scheduler.rake'正常工作.我的clock.rb进程也在运行,因为它会每30秒触发一次.但是,我遇到了clock.rb的语法问题,无法在我的'rake.scheduler'中正确运行'send_notifications'任务.这是它的样子:
# scheduler.rake
desc "This task is called by the Heroku scheduler add-on"
task :send_notifications => :environment do
puts "this test is working correctly!"
end
Run Code Online (Sandbox Code Playgroud)
这是clock.rb的样子:
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'
include Clockwork
every(30.seconds, 'Send notifications') {
# Heroku::API.new.post_ps('pocket-pal', 'rake scheduler:send_notifications')
rake scheduler:send_notifications
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我尝试使用Heroku API并调用rake进行分离过程.
当我使用Heroku API时,我收到此错误:
ERROR -- : uninitialized constant Heroku (NameError)
Run Code Online (Sandbox Code Playgroud)
当我调用rake时,我收到以下错误:
ERROR -- : undefined local variable or method `send_notifications' for main:Object (NameError)
Run Code Online (Sandbox Code Playgroud)
有谁知道这两种方法的正确语法是什么?
我是TDD,RSpec和工厂的新手,并试图了解如何测试每个用户的电话号码属性是否唯一.为此,我正在尝试在用户工厂中使用序列.以下我没有太多运气:
FactoryGirl.define do
factory :user do
number = 123456789
sequence(:phone_number) {|n| (number + n).to_s }
end
end
Run Code Online (Sandbox Code Playgroud)
有关实现这一目标的最佳方法的任何想法?此外,什么样的测试对于这样的事情是有意义的,最终我想要将以下验证添加到用户模型以进行这样的测试通过?
validates :phone_number, :uniqueness => true
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试使用link_to将变量从视图传递到控制器.以下是我在视图中的代码:
<%= link_to 'Send Chant', :controller => 'send_chants', :action => 'index', :content => @chant.content %></b>
Run Code Online (Sandbox Code Playgroud)
这是我的'send_chants'控制器中的索引操作的样子:
class SendChantsController < ApplicationController
def index(content)
puts content
end
end
Run Code Online (Sandbox Code Playgroud)
点击"发送聊天"链接后,我得到一个ArgumentError错误的参数数量(0表示1)
我确定我错过了一些简单的事情.有什么想法吗?
非常感谢!