【问题标题】:URL configuration issue with Django app using Bluehost使用 Bluehost 的 Django 应用程序的 URL 配置问题
【发布时间】:2015-03-03 05:36:17
【问题描述】:

我正在使用 Bluehost 将我的 Django 应用程序部署到生产服务器,但一直看到我网站的 404 页面。问题似乎是我的 URL 配置。当我在浏览器中输入http://www.example.com/ 时,我会收到以下信息:

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/ 会自动添加到我的 URL 的末尾我想完全消除 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")

这可能是我的文件在我的服务器上的位置的问题吗?如果有人在我之前遇到过这种问题,我将不胜感激。谢谢!

【问题讨论】:

    标签: django apache .htaccess fastcgi bluehost


    【解决方案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.
    

    【讨论】:

    • 感谢您的回复!这对于解决问题的第二部分非常有用。输入我的主 URL 现在完全按照我的意愿重定向到主页。但是在我的生产服务器上仍然会发生同样的问题。当我在浏览器中键入 www.example.com 时,我仍然收到相同的错误:(当前 URL,public_html/,与其中任何一个都不匹配)。 Public_html 仍然被附加到我的 URL 的末尾,并导致我的所有 URL 都出现问题
    • 在您的生产服务器中,您的托管服务器中可能存在另一个包含 public_html 的默认 urls.py。检查。或在您的 settings.py 中设置根 url
    • 我尝试了您的两个建议,但不幸的是它们都没有奏效。唯一的 urls.py 文件是我的项目中的文件,它按预期工作。实际上,我当前的 django 配置在使用我的开发服务器时运行良好。 public_html/ 问题只发生在我的生产服务器上。而且我一生都无法弄清楚导致 public_html/ 附加到我的 URL 的原因
    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    相关资源
    最近更新 更多