我想在我的Django应用程序中直接使用反向URL来使用管理网站,但是我遇到了这个错误:No module named admin.site.urls
我的urls.py文件如下:
import os
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from BirthCertificate import views
from Identity import views
from Accueil import views
from log import views
from Mairie import views
from Table import views
from Recensement import views
from Configurations import views
from Mariage import views
import debug_toolbar
from django.views.generic.base import TemplateView
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name=os.path.join(settings.BASE_DIR, 'Accueil/templates/Choice.html')),
name='choice'),
url(r'^admin/', include('admin.site.urls')),
url(r'^BirthCertificate/', include('BirthCertificate.urls')),
url(r'^Identity/', include('Identity.urls')),
url(r'^Accueil/', include('Accueil.urls')),
url(r'^Home/', include('log.urls')),
url(r'^Mairie/', include('Mairie.urls')),
url(r'^Table/', include('Table.urls')),
url(r'^Recensement/', include('Recensement.urls')),
url(r'^Configurations/', include('Configurations.urls')),
url(r'^__debug__/', include(debug_toolbar.urls)),
url(r'^Mariage/', include('Mariage.urls')),
]
我的一个HTML模板有:
{% if request.user|has_group:"admin" %}
<li><a href="{% url "admin" %}" ><span class="glyphicon glyphicon-log-out"></span> Administration </a></li>
{% endif %}
有什么问题吗? 我不知道如何解决这个错误..
Reverse for 'admin' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我想在我的模板中使用URL直接访问Django管理页面,这可能吗? - Essexadmin
只是命名空间。你还需要包含URL模式的名称,例如对于管理员索引,使用{% url "admin:index" %}
。 - Alasdairre_path(r'^ admin /',admin.site.urls)
。 - Graham Klynere_path()
可以工作,但是我的答案中的path()
行也应该可以,这是文档建议的方法。 - Alasdair