gpt4 book ai didi

Django 管理网址

转载 作者:行者123 更新时间:2023-12-04 13:13:02 25 4
gpt4 key购买 nike

我想在我的 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 %}

有什么问题吗?
我没有找到如何解决这个错误..

最佳答案

In Django 1.9+ ,你不需要使用 include .使用可调用的 admin.site.urls ,不是字符串 'admin.site.urls' .

url(r'^admin/', admin.site.urls),

In Django 2.0+ ,您可以使用 path()而不是 url() .
path('admin/', admin.site.urls),

In Django < 1.9你通过 admin.site.urlsinclude .
url(r'^admin/', include(admin.site.urls)),

要反转管理索引 url,请将模板中的 url 标记更改为:
{% url "admin:index" %}

关于Django 管理网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44130643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com