我加入了社區問這個問題,我相信我已經做了我尋找答案的功課我似乎沒有哪裏解決這個(希望)一個問題。如果您不這麼想,請指出正確的問題。的Django 1.5索引頁面不顯示部署服務器上(但工程開發服務器上)
我有我試圖主機使用Django 1.5的網站一分錢OS VPS,而開發它在我的MacBook Pro(OS X 10.6),它實際已安裝的Django 1.4(沒有更新過,但 - 花樣這足以讓我開始)。
我已成功地用「投票」使用nginx的和gunicorn服務器應用程序的工作部署一個試驗基地。除了主索引頁,也就是將瀏覽器指向〜my-domain.com /事實,給出了一個錯誤:「請求的URL /沒有被此服務器上找到」
但投票的應用程序,即〜my-domain.com /輪詢/,按預期方式工作。
此外,當我改變「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
我已經把我的代碼的相關部分對引擎收錄在這裏節省空間。
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我會離開出從現在起:)
感謝您的快速回復。我試過但沒有改變任何東西。造成更多混亂的是沒有日誌可供我追蹤! nginx的日誌很清晰 - 我不認爲gunicorn留下任何...... :( –