Django名称"admin"未定义 [英] Django name 'admin' is not defined
问题描述
我正在关注本教程,但遇到了一些麻烦. https://www.youtube.com/watch?v=3tf8XlhsQAo
I'm following this tutorial and i have some troubles. https://www.youtube.com/watch?v=3tf8XlhsQAo
"""mysite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
# url(r'^webapp/', include("webapp.urls")),
url(r'^$',include("personal.urls")),
]
我已经编写了上面的代码,但是执行后出现以下错误,有人可以帮助我理解此错误消息的含义吗?
I've written the code above, however when I executed I get the error below, can anyone help me understand the meaning of this error message?
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\USER\Desktop\Django\mysite\mysite\urls.py", line 24, in <modu
>
url(r'^$',include("personal.urls")),
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packa
s\django\conf\urls\__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\importlib\
init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\USER\Desktop\Django\mysite\personal\urls.py", line 5, in <mod
e>
url(r'^admin/',admin.site.urls),
NameError: name 'admin' is not defined
推荐答案
回溯告诉您 personal \ urls.py
文件中发生了错误:
The traceback is telling you that the error is occurring in your personal\urls.py
file:
File "C:\Users\USER\Desktop\Django\mysite\personal\urls.py", line 5, in <mode>
url(r'^admin/',admin.site.urls),
您已经在 mysite \ urls.py
中添加了管理网址,您不应在 personal \ urls.py
中包含管理员网址.从 personal \ urls.py
中删除该行.
You have already included the admin urls in mysite\urls.py
,
you should not include the admin urls in personal\urls.py
. Remove that line from personal\urls.py
.
这篇关于Django名称"admin"未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!