2013-03-11 100 views
1

我有一個Django應用程序,我試圖部署。 Apache的設置配置中,我通過以下網址訪問我的WSGI應用程序的方式:正確的方式來處理HttpResponseRedirect

sitename.com/~amartino 

含義,我只有在我的public_html目錄wsgi.py文件。

sitename.com/~amartino/expofit 

對於在urls.py.其設置方式: 我通過URL來訪問我的網站的Django

urlpatterns = patterns('', 
('/param_select/$',session_check(param_select)), 
('registration/$',registration), 
('result_show/(\d+)',session_check(result_show)), 
('^expofit/$',media_clean(start)), 
('result_pick/$',session_check(result_pick)), 
('mail_report/$',session_check(mail_report)), 
('notification/$',session_check(notification)), 

但是,我得到(這並沒有發展出現:))問題是,我使用的views.py硬編碼HttpResponseRedirect。

... 
#If all fields are valid 
return HttpResponseRedirect('/expofit/param_select/') 
#else reload page 
... 

由於生產環境不把我的網站的URL的根,我現在有錯誤,因爲上HttpResponseRedirect轉化爲

sitename.com/expofit/param_select/ 

其不被認可的Apache 。

我想我可以去掉斜線和有:

return HttpResponseRedirect('expofit/param_select/') 

這將導致:

sitename.com/~amartino/expofit/registration/expofit/param_select/ 

但這似乎做正確的方式不適合我竟又很快就會有一個巨大的網址。 這裏的設計/配置缺陷在哪裏?

+0

你可以使用快捷方式'redirect'並讓'urls.py'處理URL https://docs.djangoproject.com/en/1.4/topics/http/shortcuts/#redirect – 2013-03-11 16:45:17

回答

4

「的問題,我收到我使用硬編碼HttpResponseRedirect」

好了,不這樣做,那麼。這就是爲什麼Django提供了reverse函數,它會將您的url名稱和計算正確的絕對URL。

相關問題