【发布时间】:2016-01-03 10:21:43
【问题描述】:
我已经使用 Django(1.8.5) 构建了一个实时通知应用程序。我正在使用 django 服务器,Nodejs 作为推送服务器,ishout.js[nodejs+redis +express.js API]。所以我按照说明安装了它们。
请建议如何修复此错误:
settings.py 文件
"""
#Django settings for realtimenotif project.
Generated by 'django-admin startproject' using Django 1.8.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# 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 = 'gvvs-0*-cohfbm@()*nyt&0u!77sc_8vnw%1afpkmhi&y-6&ds'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ADMINS = (
#'arunsingh','arunsingh.in@gmail.com'
)
MANAGERS = ADMINS
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'drealtime',
'sendnotif',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'drealtime.middleware.iShoutCookieMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'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 = 'realtimenotif.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'debug':DEBUG,
'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 = 'realtimenotif.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'),
#The following settings are not used with sqlite3:
'USER':'',
'PASSWORD':'',
'HOST':'', # Empty for localhost through domain sockets,127.0.0.1
'PORT':'', # Set to empty string for default
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
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/'
urls.py 文件
"""realtimenotif URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import patterns, include, url
#from sendnotif.views import home, alert
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns(['',
url(r'^$', 'sendnotif.views.home', name='home'),
#url(r'^$', home, name='home'),
url(r'^alert/$', 'sendnotif.views.alert', name='alert'),
#url(r'^alert/$', alert, name='alert'),
url(r'^accounts/login/$','django.contrib.auth.views.login',name='login'),
#uncomment the next line to enable the admin:
url(r'^admin/$', include(admin.site.urls)),
] )
Django 服务器正在启动,它说可以工作并给出此消息
“您看到此消息是因为您的 DEBUG = True Django 设置文件,您还没有配置任何 URL。到达 工作!”
我必须在我的 settings.py 和 views.py 文件中进行哪些更改,请建议解决方法。我已经阅读了official django documentation 和初学者教程,但无济于事。
您可以在githubRepo查看项目源代码
【问题讨论】:
-
您应该解决(并阅读)该问题中的 cmets 并相应地更新/编辑您的问题,而不是 deleting your question 并创建一个新问题
-
请不要发布指向您的存储库的链接并要求我们修复您的代码。在 Stack Overflow 上发布相关代码。您可能会发现完成本教程并让简单的民意调查应用程序运行起来更容易,而不是一次性安装 Django、node、ishout 等。
-
@Alasdair 我根本没有要求修复代码,那个 repo 只是为了注意,下次开始,我会尽力发布相关代码,上一个问题的版主建议它是不专注于一个问题,而是问题很广泛,因此我试图通过缩小问题来解决这个问题。
-
您关注的是一个错误,但您没有向我们展示导致问题的代码。目前,您要求我们去查看您的存储库以找出问题所在。您可以edit您的问题并添加相关代码。特别是,您需要在设置中显示
ROOT_URLCONF是什么,并显示它指向的 urls.py 的内容。 -
我只是尝试添加代码,但编辑没有完成,请指出问题。
标签: python django node.js sqlite