2015-01-05 22 views
0

我正在使用Bluehost將我的Django應用程序部署到生產服務器,但繼續看到我的網站的404頁面。這個問題似乎是我的URL配置。當我鍵入http://www.example.com/到我的瀏覽器,我收到以下內容:使用Bluehost的Django應用程序的URL配置問題

Request URL: http://www.example.com/public_html/ 

^main/ 
^admin/ 
^accounts/ 
^media/(?P<path>.*)$ 
etc.. 

The current URL, public_html/, didn't match any of these 

的public_html /自動添加到我的網址的結尾,我想消除的public_html /完全是這樣的預期我的URL模式會工作。例如

Request URL: http://www.example.com/ 

這將然後重定向到

Request URL: http://www.example.com/main/ 

我將如何去改變從http://www.example.com/public_html/的默認http://www.example.com/

我FCGI文件:

AddHandler fcgid-script .fcgi 
RewriteEngine on 
RewriteBase/
RewriteRule ^(media/.*)$ - [L] 
RewriteRule ^(adminmedia/.*)$ - [L] 
RewriteCond %{REQUEST_URI} !(cgi-bin/mysite.fcgi) 
RewriteRule ^(.*)$ cgi-bin/mysite.fcgi/$1 [L] 

我的.htaccess文件:

#!/home/username/python/bin/python 
import sys, os 

sys.path.insert(0, "/home/username/python") 
sys.path.insert(13, "/home/username/MySite") 

os.environ['DJANGO_SETTINGS_MODULE'] = 'MySite.settings' 

from django.core.servers.fastcgi import runfastcgi 

runfastcgi(method="threaded", daemonize="false") 

是否有這可能是跟在我的文件位於我的服務器上一個問題的可能性?如果有人遇到過這種問題,我會非常感謝一些建議。謝謝!

回答

1

你必須定義按照你的urls.py網址,

url(r'^$', 'views.home', name='home') 
url(r'^main/$', 'views.main', name='main') 

然後在views.py

def home(request): 
    return HttpResponseRedirect('/main/') 

def main(request): 
    #some code here. 
+0

感謝您的答覆!這對於解決問題的第二部分非常有用。在我的主URL中鍵入現在可以按照我的意願重定向到主頁面。然而,在我的生產服務器上,同樣的問題仍然存在當我在瀏覽器中鍵入www.example.com時,我仍然收到相同的錯誤: (當前URL public_html /不匹配其中任何一個)。 Public_html仍然被追加到我的URL末尾並導致我的所有URL都有問題 –

+0

在您的生產服務器中,可能在您的託管服務器中存在另一個包含public_html的默認urls.py。覈實。 或在你的settings.py中設置root url url – jatin

+0

我試過了你的兩條建議,不幸的是他們都沒有工作。唯一的urls.py文件是我的項目中的那些,它按預期工作。實際上,我使用我的開發服務器時,我的當前django配置完美。 public_html /問題只發生在我的生產服務器上。而且我不能爲我的數字找出導致public_html /被追加到我的網址的原因 –