简体   繁体   English

Django管理站点激活

[英]Django Admin Site Activation

I have been working on the Django tutorial and everything has gone perfect so far. 我一直在研究Django教程,到目前为止一切都很完美。

However in part 2, which teaches how to deal with the admin site, I encountered a problem. 然而,在第2部分,教我如何处理管理站点,我遇到了一个问题。

After uncommenting the lines for activating the admin site as told in the tutorial I tried to activate the server and proceeded to the admin site to see the following error: 在取消注释激活管理站点的行后, 如教程中所述,我尝试激活服务器并进入管理站点以查看以下错误:

DoesNotExist at /admin/
Site matching query does not exist

Well, with some googling I managed to resolve it by commenting the line in settings.py: 好吧,通过一些谷歌搜索,我设法通过在settings.py中注释该行来解决它:

'django.contrib.sites'

Everything seemed to work fine after doing this, but I guess this is a problem since uncommenting this line is not mentioned in the tutorial 这样做之后似乎一切正常,但我想这是一个问题,因为在教程中没有提到取消注释这一行

Django: 1.4.3 Django:1.4.3

Python: 2.7.3 Python:2.7.3

Uncomment django.contrib.sites and run syncdb command. 取消注释django.contrib.sites并运行syncdb命令。 If you have already done that and it doesn't seem to work and you still want to leave sites app uncommented then: 如果您已经这样做了并且它似乎不起作用并且您仍然希望将sites app取消注释,那么:

Run ./manage.py shell 运行./manage.py shell

from django.contrib.sites.models import Site
Site.objects.create()

After that everything should be just fine. 之后一切都应该没问题。 If you would like to modify the new Site record, you can do that in Django admin section sites . 如果您想修改新站点记录,可以在Django管理部门sites

在runserver之前的Python manage.py syncdb

create a user if it is not done yet: 如果尚未完成,请创建一个用户:

python manage.py createsuperuser

add to the file settings.py: 添加到文件settings.py:

 INSTALLED_APPS = [
    ...
    'django.contrib.sites',
    ...

] ]

and in the bash run : 并在bash运行中:

python manage.py migrate

and enjoy ! 享受 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM