Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.8 AttributeError:模块没有属性';网址';_Python_Django_Python Import_Django 1.8 - Fatal编程技术网

Python Django 1.8 AttributeError:模块没有属性';网址';

Python Django 1.8 AttributeError:模块没有属性';网址';,python,django,python-import,django-1.8,Python,Django,Python Import,Django 1.8,我正在做一个显示“hello world!”的练习,但当我打开网站时,django给出了一个例外。我该如何解决这个问题 例外情况是: AttributeError at / module 'apps.release_news' has no attribute 'urls' Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.8.7 Exception Type: AttributeError

我正在做一个显示“hello world!”的练习,但当我打开网站时,django给出了一个例外。我该如何解决这个问题

例外情况是:

AttributeError at /
module 'apps.release_news' has no attribute 'urls'
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.7
Exception Type: AttributeError
Exception Value:    
module 'apps.release_news' has no attribute 'urls'
Exception Location: C:\software\development\PythonProject\DemoGuitarProject\DemoGuitarProject\urls.py in <module>, line 24
Python Executable:  C:\software\development\python3.5\python.exe
Python Version: 3.5.0
Python Path:    
['C:\\software\\development\\PythonProject\\DemoGuitarProject',
 'C:\\software\\development\\PythonProject\\DemoGuitarProject',
 'C:\\software\\development\\python3.5\\python35.zip',
 'C:\\software\\development\\python3.5\\DLLs',
 'C:\\software\\development\\python3.5\\lib',
 'C:\\software\\development\\python3.5',
 'C:\\software\\development\\python3.5\\lib\\site-packages']
Server time:    Wed, 2 Dec 2015 15:49:02 +0800
目录DemoGuitarProject中的My URL.py是:

from django.conf.urls import include, url
from django.contrib import admin

from apps import release_news

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^release_news/', include(release_news.urls)), 
]
我的URL.py应用程序目录发布的新闻是:

from django.conf.urls import include, url

from apps.release_news import views

__author__ = 'Kami Wan'

urlpatterns = [

    url(r'^$', views.index, name='index'),                      
    url(r'^summernote/', include('django_summernote.urls')),  
]
My views.py文件是:

# Create your views here.
from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello world ! ")
My settings.py文件:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xxxxxx'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'suit',  # admin theme plugin
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.release_news',  # release news
    'django_summernote',  # RTE plugin
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'DemoGuitarProject.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'DemoGuitarProject.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

# --------------------------------------------user setting area---------------------------------------------------------

# choose a settings file to use
os.environ['DJANGO_SETTINGS_MODULE'] = 'DemoGuitarProject.settings'

# set the directory for uploading
MEDIA_URL = "upload/"
MEDIA_ROOT = os.path.join(BASE_DIR, "upload")

# TEMPLATE zh_CN
FILE_CHARSET = "utf-8"
DEFAULT_CHARSET = 'utf-8'

代码来自DemoGuitarProject/url.py

from apps import release_news
from apps.release_news import urls as release_news_urls

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^release_news/', include(release_news_urls)), 
]
读取文件
apps/release\u news/\uuuuuu init\uuuuuuu.py

from apps import release_news
from apps.release_news import urls as release_news_urls

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^release_news/', include(release_news_urls)), 
]
我猜这个文件是空的。添加到此文件:

from apps.release_news import urls
或者更改
DemoGuitarProject/url.py

from apps import release_news
from apps.release_news import urls as release_news_urls

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^release_news/', include(release_news_urls)), 
]

@Sayse我刚刚尝试删除密钥,但仍然无法正常工作,因为给出了一个异常:raise INPROPERLYCONFIGURED(“密钥设置不能为空”)@KamiWan,@Sayse希望您从发布的代码中删除
密钥,它可能被利用。您不应该在可公开访问的代码中包含这样的敏感数据。@mic4ael,@Sayse我已经这样做了。感谢您提醒我。虽然您已从问题中删除了密钥,但它仍会显示在编辑历史记录中。在应用程序中更改密钥也是一个好主意。不用担心,我已经删除了我的评论,这样人们在编辑历史记录中搜索的时间就少了。至少,我鼓励以上所有人也这样做。这也是所有噪音远离你的实际问题你的猜测是正确的,你的建议真的工作!我仍然不明白为什么使用“from apps import release_news”语句不能让django在release_news目录中找到url.py文件?理解导入机制的最佳地方: