我正在尝试完成Django教程,我的代码中的所有内容都在工作,直到我尝试保存并打印对象的实例变量.
这是我的类的代码(这是在我的应用程序的models.py文件中):
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
Run Code Online (Sandbox Code Playgroud)
然后我把它输入终端:
$ python manage.py sql polls
Run Code Online (Sandbox Code Playgroud)
返回此输出:
BEGIN;
CREATE TABLE `polls_question` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`question_text` varchar(200) NOT NULL,
`pub_date` datetime NOT NULL
)
;
CREATE TABLE `polls_choice` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`question_id` integer NOT NULL,
`choice_text` varchar(200) NOT NULL,
`votes` integer NOT NULL
)
;
ALTER TABLE `polls_choice` ADD CONSTRAINT `question_id_refs_id_f3f98eca` FOREIGN KEY (`question_id`) REFERENCES `polls_question` …Run Code Online (Sandbox Code Playgroud) 我将我的Django应用托管在Heroku上,并且我的域名已在Network Solutions中注册。输入域名即www.example.com时,Heroku显示:
"Not Found
The requested URL / was not found on this server."
Run Code Online (Sandbox Code Playgroud)
然后,我必须导航到显示应用程序登录页面的模板URL,即www.example.com/shipment/。
如何获得我的根域www.example.com以自动重定向到www.example.com/shipment/,或者将/ shipment /的URL更改为我的根域?
这是我的应用程序的urls.py:
from django.conf.urls import patterns, url
from shipment import views
urlpatterns = patterns('',
url(r'^$', views.landing, name='landing'),
url(r'^create-subscription/$', views.createSubscription, name='createSubscription'), #
url(r'^(?P<subscription_duration>\d+)/create-account/$', views.createAccount, name='createAccount'),
url(r'^create-account/pay/$', views.pay, name='pay'),
url(r'^create-account/confirm/$', views.confirm, name='confirm'),
)
Run Code Online (Sandbox Code Playgroud)
这是我的项目的urls.py:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'subscription.views.home', name='home'),
# …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行一个函数,条件是触发它的输入不是提交类型.
$(document).ready(function() {
//triggers the capture() function whenever any input on the page loses focus
$("input").blur(function() {
// This is the part that's not working. I need to check if the specific input that
// triggered the code to run is of type submit.
if (("input").type == 'submit') {
alert("this worked");
}
else {
capture();
}
});
});
Run Code Online (Sandbox Code Playgroud)
现在,即使我模糊了提交类型的输入,也会调用capture().我希望这个代码在类型为submit的输入触发外部函数运行时触发第一个条件语句.