2015-05-10 64 views
-2

阿羅哈CHAPS,Django的教程惡作劇

經與Django的教程

https://docs.djangoproject.com/en/1.8/intro/tutorial01/

有一點小毛病正如你可以看到下面,它說「問題」沒有定義。

c:\Python34\Scripts\mysite>python manage.py makemigrations polls 
Traceback (most recent call last): 
File "manage.py", line 10, in <module> 
execute_from_command_line(sys.argv) 
File "c:\Python34\lib\site-packages\django\core\management\__init__.py",  line 
338, in execute_from_command_line 
utility.execute() 
File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line 
312, in execute 
django.setup() 
File "c:\Python34\lib\site-packages\django\__init__.py", line 18, in setup 
apps.populate(settings.INSTALLED_APPS) 
File "c:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate 
app_config.import_models(all_models) 
File "c:\Python34\lib\site-packages\django\apps\config.py", line 198, in import_models 
self.models_module = import_module(models_module_name) 
File "c:\Python34\lib\importlib\__init__.py", line 109, in import_module 
return _bootstrap._gcd_import(name[level:], package, level) 
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import 
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load 
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked 
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked 
File "<frozen importlib._bootstrap>", line 1129, in _exec 
File "<frozen importlib._bootstrap>", line 1471, in exec_module 
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed 
File "c:\Python34\Scripts\mysite\polls\models.py", line 3, in <module> 
class Question(models.Model): 
File "c:\Python34\Scripts\mysite\polls\models.py", line 7, in Question 
class Choice(models.Model): 
File "c:\Python34\Scripts\mysite\polls\models.py", line 8, in Choice 
question = models.ForeignKey(Question) 
NameError: name 'Question' is not defined 

這裏是我的models.py文件提前

from django.db import models 

class Question(models.Model): 
question_text = models.CharField(max_length=200) 
pub_date = models.DateTimeField('date published') 

class Choice(models.Model): 
    question = models.ForeignKey(Question) 
    choice_text = models.Charfield(max_length=200) 
    votes = models.IntegerField(default=0) 

感謝所有幫助

+1

如果這是你確切的文件,我很驚訝它沒有叫喊關於縮進錯誤! – karthikr

回答

2

不嵌套類。讓你的縮進級別正確。選擇需要與問題處於同一水平,而不是問題內部。這裏的錯誤縮進和堆棧跟蹤會將其刪除。

+0

謝謝Stefan解決了它。對於新問題抱歉 – Tinytim

1
from django.db import models 

class Question(models.Model): 
    question_text = models.CharField(max_length=200) 
    pub_date = models.DateTimeField('date published') 

class Choice(models.Model): 
    question = models.ForeignKey(Question) 
    choice_text = models.Charfield(max_length=200) 
    votes = models.IntegerField(default=0) 

Identation是問題