- can not find module
1 startapp appname 而不是 startproject
2 不要自己创建项目根目录,要用mamage.py生成
- can not find app:
因为copy code而误删modell里的:from __future__ import unicode_literals
- doesn't declare an explicit app_label
Traceback (most recent call last):
File "<input>", line , in <module>
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line , in do_import
module = self._system_import(name, *args, **kwargs)
File "C:/Users/tianhang/PycharmProjects/WebApp\app_hyperlink\models.py", line , in <module>
class Snippet(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line , in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class app_hyperlink.models.Snippet doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
解决方法:在model添加 app_label = 'app_hyperlink'
class Snippet(models.Model):
owner = models.ForeignKey('auth.User', related_name='snippet_user2')
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
code = models.TextField()
linenos = models.BooleanField(default=False)
language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100) class Meta:
ordering = ('created',)
app_label = 'app_hyperlink'