我加入了社区提出这个问题,我相信我已经完成了我在寻找答案的功课,我似乎无法解决这个(希望是)一个问题 . 如果您不这么认真,请指出正确的问题 .
我有一个Cent OS VPS,我试图使用Django 1.5主持一个网站,同时在我的MacBook pro(OS X 10.6)上开发它实际安装了Django 1.4(还没有更新它 - 认为它就足够了让我开始) .
我已经设法使用nginx和gunicorn服务器使用“民意调查”应用程序部署测试站点 . 除了主索引页面(即将浏览器指向~my-domain.com /)这一事实外,它给出了一个错误:
“在此服务器上找不到请求的URL / . ”
但民意调查应用程序,即~my-domain.com / polls /,正在按预期工作 .
此外,当我更改“settings.py”以使DEBUG = TRUE并使用该命令时
> python manage.py runserver 0.0.0.0:8001
要在部署计算机(VPS)上运行开发服务器,索引页面正在运行 . 当我在Mac上使用runserver时,我也可以看到索引页面 .
我的项目层次结构如下:
+dj_site
|- manage.py
|+dj_site
||-__init__.py
||-settings.py
||-urls.py
||-views.py
||-wsgi.py
|+index
||-__init__.py
||-models.py
||-settings.py
||-urls.py
||-views.py
||-tests.py
||+templates
|||+index
||||-index.html
|+polls
||-__init__.py
||-models.py
||-settings.py
||-urls.py
||-views.py
||-tests.py
||+static
|||+polls
||||-style.css
||+templates
|||+index
||||-index.html
|+proj_static
||-base.css
|+media
||-foo.txt
我已将代码的相关部分放在pastebin上以节省空间 .
dj_site / urls.py:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
# Home /
url(r'^$', include('index.urls', namespace="index")),
# for Polls app
url(r'^polls/',include('polls.urls', namespace="polls")),
)
dj_site /索引/ urls.py:
from django.conf.urls import patterns, url
from index import views
urlpatterns = patterns('',
# ex:/
url(r'^$',views.IndexView.as_view(), name='index'),
)
dj_site /索引/ views.py
from django.http import HttpResponseRedirect, HttpResponse
from django.views.generic import TemplateView
class IndexView(TemplateView):
template_name = "index/index.html"
很抱歉这条长信息,但任何指向正确方向的信息都将不胜感激 . 我错过了什么?
预先感谢您的帮助 .
编辑
对不起伙计们,我解决了这个问题 .
查看右边的建议链接,我会看到:Django dev server works, apache not
所以我重新启动了gunicorn和nginx服务器 . Gunicorn作为守护进程运行所以我认为我不需要重新启动它 - 但这解决了我的错误 .
如果某人正在经历相同的情况,以下命令对我有用:
> sudo service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
> ps ax | grep gunicorn
17211 ? S 0:00 /usr/bin/python /usr/bin/gunicorn dj_site.wsgi:application -- bind=127.0.0.1:<port> --daemon
17216 ? S 0:00 /usr/bin/python /usr/bin/gunicorn dj_site.wsgi:application --bind=127.0.0.1:<port> --daemon
17218 pts/0 S+ 0:00 grep gunicorn
> kill 17211
> kill 17216
> gunicorn dj_site.wsgi:application --bind=127.0.0.1:<port> --daemon
所以它与Django设置没什么关系,但是谢谢你@Ranju我将从现在开始忽略了doller标志:)
1 回答
在您的urls.py文件中,进行更改
至
即,删除$符号 .