调试过程出现的问题:

调试过程出现的问题:

  1. 启动出现错误 'Specifying a namespace in include() without providing an app_name ’
    django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the lis
    t of patterns and app_name instead.

解释:是因为urls中的#django2.1版本该修了include参数 必须是元祖
https://blog.csdn.net/a1007720052/article/details/82108994
错误写法:
urlpatterns = [
url(’’, include((‘apps.urls’, ‘apps’), namespace=‘apps-urls’)),
]
正确写法:
urlpatterns = [
url(’’, include((‘apps.urls’, ‘apps’), namespace=‘apps-urls’)),
]

  1. 使用runserver 0.0.0.0:8000启动后,点击浏览器提示无法访问,拒绝访问:
    解决办法: 用127.0.0.1:8000访问,默认地址是0.0.0.0:8000故访问不到。

3.创建表时报错:
File “C:\Pyxuexi\GithubCode\guest\sign\models.py”, line 20, in Guest
event = models.ForeignKey(Event)
TypeError: init() missing 1 required positional argument: ‘on_delete’
分析:event = models.ForeignKey(Event)在django2以后,强调了使用ForeignKey必须指定on_delete=models.CASCADE(级联删除,关系表中使用级联表)
正确写法:
class Guest(models.Model):
event = models.ForeignKey(Event,on_delete=models.CASCADE)

  1. 问题:
    django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
发布了23 篇原创文章 · 获赞 0 · 访问量 577

猜你喜欢

转载自blog.csdn.net/cbiexi/article/details/104471981
今日推荐