我试图遵循Polls教程,包括来自项目的urls.py
,以及Polls目录中的models.py
。在
q = Question(question_text="some text", pub_date=timezone.now))
导致以下错误:
^{pr2}$我的网站/网址.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
投票/模型.py
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
如果您在djangoshell中执行此操作,首先需要导入正在使用的模型,在您的示例中,您需要导入model问题
让我们从头开始回忆一切。在
第1步:激活外壳
第2步:导入模型问题,同时导入时区
^{pr2}$第3步:现在运行查询
如果你注意到了,根据你的问题,这里是你做错了什么。在
第4步:运行保存方法
所有这些都是w.r.tPolls Tutorial在玩api。在
我认为在学习教程的过程中,您已经做了很多代码更改,而这些并没有反映在sql数据库中。在
所以,在做以上步骤之前,请遵循下面的步骤。在
现在就这么做
^{pr2}$相关问题 更多 >
编程相关推荐