Python Django网页可以手动工作,但域在共享主机上出现404错误

时间:2016-01-17 19:49:36

标签: python django shared-hosting

我正在使用justhost(共享主机)在我的子域dev.domain_name.com上测试python django网页

我使用了以下教程:http://flailingmonkey.com/install-django-justhost/来获得以下输出。

获取以下内容的命令:python mysite.fcgi

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
X-Frame-Options: SAMEORIGIN
Content-Type: text/html


<!DOCTYPE html>
<html lang="en"><head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="robots" content="NONE,NOARCHIVE"><title>Welcome to Django</title>
  <style type="text/css">
    html * { padding:0; margin:0; }
    body * { padding:10px 20px; }
    body * * { padding:0; }
    body { font:small sans-serif; }
    body>div { border-bottom:1px solid #ddd; }
    h1 { font-weight:normal; }
    h2 { margin-bottom:.8em; }
    h2 span { font-size:80%; color:#666; font-weight:normal; }
    h3 { margin:1em 0 .5em 0; }
    h4 { margin:0 0 .5em 0; font-weight: normal; }
    table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
    tbody td, tbody th { vertical-align:top; padding:2px 3px; }
    thead th {
      padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
      font-weight:normal; font-size:11px; border:1px solid #ddd;
    }
    tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
    #summary { background: #e0ebff; }
    #summary h2 { font-weight: normal; color: #666; }
    #explanation { background:#eee; }
    #instructions { background:#f6f6f6; }
    #summary table { border:none; background:transparent; }
  </style>
</head>

<body>
<div id="summary">
  <h1>It worked!</h1>
  <h2>Congratulations on your first Django-powered page.</h2>
</div>

<div id="instructions">
  <p>
    Of course, you haven't actually done any work yet. Next, start your first app by running <code>python manage.py startapp [app_label]</code>.
  </p>
</div>

<div id="explanation">
  <p>
    You're seeing this message because you have <code>DEBUG = True</code> in your Django settings file and you haven't configured any URLs. Get to work!
  </p>
</div>
</body></html>


Tech Stack:
Python 2.7.2
flup 1.0.2
django 1.8.7

**My subdomain dev.domain_name.com returns:**
Not Found The requested URL /mysite.fcgi/ was not found on this server.

Below is .htaccess & mysite.fcgi

[~/public_html/subdomaindirectory]# vi mysite.fcgi
#!/home2/findity/python/bin/python
import sys, os

sys.path.insert(0, "/home2/findity1/python")

path = '/home2/findity1/public_html/findityaardev/mysite'
if path not in sys.path:
   sys.path.append(path)

print(sys.path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")


.htaccess file:
[~/public_html/subdomaindirectory]# vi .htaccess

AddHandler fcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /mysite.fcgi/$1 [QSA,L]

注意:我从cpanel添加了.fcgi apache处理程序,它将我从500内部服务器错误带到404.它看起来像是根据命令手动工作但是我无法看到它的子域。如果需要更多信息,请告诉我。

2 个答案:

答案 0 :(得分:0)

首先查看Django 1.8 documentation中的注释:

  

自1.7版以来:
  不推荐使用FastCGI支持,将在Django 1.9中删除。

因此可能会选择其他方法。

我注意到您的Object有一个打印声明。删除它,我不认为fastcgi进程可以访问stdout(it goes to the server instead)。这可能会导致问题。

如果这不能解决问题,首先要尝试识别错误的位置。我认为最有可能发生在以下某个地方:

  • 重定向无效。
  • 或者Apache无法找到mysite.fcgi
  • 或者mysite.fcgi调用返回404的Django。
  • 也许Django正在工作,但使用的是返回404的视图。

查看Apache mysite.fcgi文件,看看是否有关于哪一个是问题区域的任何线索。

答案 1 :(得分:0)

接下来是我的.htaccess和django.fcgi文件 这些文件在JustHost中正常工作。 我目前正在使用此配置在Justhost中运行3个Django支持的网站。

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django.fcgi/$1 [QSA,L]

我使用的是简约的.fcgi文件(在我的情况下是django.fcgi)

#!/home/.../venv/bin/python
# DO NOT USE SOMETHING LIKE THIS #!/usr/bin/env python
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/.../django_project_directory")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "my_project_name.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

编辑:
我正在使用Django 1.8.x.我目前没有Django 1.9.x

的任何项目