对于管理站点,django“异常值:没有名为urls的模块”

时间:2013-09-25 13:57:49

标签: python django

我是django新手,试图按照教程。当我试图访问django管理网站时

        http://127.0.0.1:8000/admin/

为下面的代码

提供错误“Exception Value:No module named 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流程上发布@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但没有奏效。

3 个答案:

答案 0 :(得分:1)

include admin urls,请使用:

from django.contrib import admin

admin.autodiscover()

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

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

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

总的来说,我会重新审视网址格式。由于您要包含其他网址,^admin\/?$最后不应该有$

此外,^admin/应该足够了

答案 1 :(得分:0)

另外,请确保不要将/ admin URL保留为/ admin。我会改变它。否则,有人可能会试图强行登录或查找后端漏洞。 :)

答案 2 :(得分:0)

karthikr的回答是首先要检查的。还要确保您的项目文件夹包含在sys.path中。我在使用开发环境(Aptana)时尝试这个,并且不得不更改工作区文件夹名称以避免命令行问题(Aptana生成的默认工作区文件夹充满了空格:'Aptana Studio 3 Workspace' )。因此,框架正在查找不存在的文件夹。

当然,这是一种愚蠢的疏忽,但如果你像我一样崭露头角,至少值得一看。