gpt4 book ai didi

python - django "Exception Value: No module named urls"用于管理站点

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:05 25 4
gpt4 key购买 nike

我是 django 新手,正在尝试遵循教程。当我尝试访问 django 管理站点时

        http://127.0.0.1:8000/admin/

对于以下代码,它给出错误“异常值:没有名为 urls 的模块”

    #uls.py
from django.conf.urls import *
from mysite.views import *
# Uncomment the next two lines to enable the admin:

# from django.contrib import admin
# admin.autodiscover()
#TODO ADD LIST OF URL
urlpatterns = patterns('',
(r'^home\/?$',get_homepage),
(r'^admin\/?$',include('django.contrib.admin.urls')),
)

我已经尝试了 stackover flow @last 发布的多种解决方案,解决了问题

    #settings.py
ROOT_URLCONF = 'mysite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'
TEMPLATE_DIRS = (
'/home/abuzzar/djcode/mysite/mysite/template',
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.sessions',
#'django.contrib.sites',
#'django.contrib.messages',
#'django.contrib.staticfiles',
'mysite.jobpost',
'django.contrib.admin',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

错误:http://pastebin.com/RMvzPd61

我尝试了解决方案:Django 1.5.1 'ImportError: No module named urls' when running tests但没有成功。

最佳答案

include admin urls ,使用这个:

from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)

或者,要解决您的问题,请在 adminurl 之间添加 site

(r'^admin\/?$',include('django.contrib.admin.site.urls'))

总的来说,我会重新审视 URL 模式。 ^admin\/?$ 不应在末尾包含 $,因为您要包含另一个 url conf。

另外,^admin/应该足够了

关于python - django "Exception Value: No module named urls"用于管理站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19007000/

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