我正在做一个练习以显示“你好世界!”,但是当我打开网站时,django发出异常。我该怎么做才能解决问题?
例外是:
DemoGuitarProject
__init__.py
settings.py
urls.py
wsgi.py
apps
release_news
__init__.py
admin.py
models.py
tests.py
urls.py
views.py
__init__.py
templates
...
我的项目结构是:
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)),
]
我在目录DemoGuitarProject中的urls.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')),
]
我在应用程序目录release_news中的urls.py是:
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world ! ")
我的views.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'
我的settings.py文件:
<?php
// my connection here
?>
<?php
$query = $mysqli->query("SELECT * FROM products");
echo '<select>';
while($obj = $query->fetch_object()){
echo '
<option value"'.$obj->product_name.'">'.$obj->product_name.'</option>
';
}
echo '</select>';
// if product1 is selected, the price is 100 and show in the textbox
//
?>
答案 0 :(得分:0)
来自DemoGuitarProject/urls.py
的代码
from apps import release_news
读取文件apps/release_news/__init__.py
我猜这个文件是空的。添加到此文件:
from apps.release_news import urls
或更改DemoGuitarProject/urls.py
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)),
]