本文介绍了Django的共享主机安装问题,404管理URL,urls.py被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有共同主办的设置Django的,这里是我的设置(为什么共同主办因为它是GoDaddy的?):

I have setup django on shared hosting (why shared hosting? Because it's godaddy), here is my setup:

一个虚拟Python环境具有以下特性:

A virtual python environment that has the following properties:

-bash-3.2$ cd
-bash-3.2$ source pyenv/bin/activate
(pyenv)-bash-3.2$ python
Python 2.7.3 (default, May 25 2012, 16:43:26)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 4, 3, 'final', 0)

在我的文档根目录,我有一个名为 mysite.cgi

In my docroot, I have a file called mysite.cgi :

#!/bin/bash
source ~/pyenv/bin/activate
python ~/code/django_cgi.py 2>&1

文件〜code / django_cgi.py看起来是这样的:

The file ~code/django_cgi.py looks like this:

#!~/pyenv/bin/python
import sys, os

sys.path.insert(0, "/full/path/to/mysite")
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

的mysite / mysite的/ settings.py 包含

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
ROOT_URLCONF = 'mysite.urls'

的mysite / mysite的/ urls.py ,我有这样的:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
)

最后,在文档根目录中的.htaccess看起来是这样的:

Finally the .htaccess in docroot looks like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/mysite.cgi
RewriteRule ^(.*)$ /mysite.cgi [QSA,L,PT]

现在,当我尝试获取 http://example.com/ 我得到一个蟒蛇404这很好。

Now when I try to fetch http://example.com/ I get a python 404 and that's fine.

然而,当我尝试获取 http://example.com/admin/ 我仍然得到这个错误

However when I try to fetch http://example.com/admin/ I still get this error:

Page not found (404)
Request Method: GET
Request URL:    http://example.com/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

那么,哪里还有问题吗?我注意到:

So, where's the problem? I note that:

在错误消息中的请求URL被列为http://example.com/,而不是http://example.com/admin/。难道htaccess的重写工作不?还是有一个问题 urls.py

The Request URL in the error message is listed as "http://example.com/" and not "http://example.com/admin/". Is the htaccess rewrite not working? Or is there a problem in the urls.py?

(我遵循的指示安装Django的网站上GoDaddy的了解这一点)

补充说明,这将有助于隔离问题:

Additional note that would help isolating the issue:

-bash-3.2$ source pyenv/bin/activate
(pyenv)-bash-3.2$ cd ~/code/mysite
(pyenv)-bash-3.2$ python manage.py runserver
Validating models...

0 errors found
Django version 1.4.3, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[14/Jan/2013 08:37:34] "GET /admin HTTP/1.0" 301 0
[14/Jan/2013 08:37:35] "GET /admin/ HTTP/1.0" 200 2012

的wget http://127.0.0.1:8000/admin 的取我正确的 index.html的登录页面管理员。

wget of http://127.0.0.1:8000/admin fetches me the correct index.html login page for admin.

我发现了一个similar 这里报告从四个月前,但具有不同的主机的问题,但没有任何反应,这个问题尚未要么。

I found a similar question reported here from four months ago but with a different host, however there are no responses to that question yet either.

推荐答案

一百万年前,我不得不添加此黑客的settings.py。我不知道它是否仍然是相关的,我没有使用任何FCGI多,但切换到gunicorn / nginx的和Apache / nginx的。

A million years ago, I had to add this hack to settings.py . I don't know whether it is still relevant, I'm not using fcgi any more, but switched to gunicorn/nginx and apache/nginx.

# hacky solution in order to get lighttpd to work
# To prevent .../django.fcgi/... from popping up again and again in the url.
FORCE_SCRIPT_NAME=""

这篇关于Django的共享主机安装问题,404管理URL,urls.py被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:52