使用 mod_python 在子目录中配置 Django 项目。管理员不工作

发布于 2024-08-03 05:50:55 字数 1684 浏览 6 评论 0原文

嗨,大家好。我试图在根目录的子目录中配置我的 django 项目,但没有让事情正常工作。(本地它工作完美)。我按照 django 官方 django 文档使用 mod_python 部署了一个项目。真正的问题是,每当我尝试进入管理员或应用程序的任何视图时,我都会收到“找不到页面”错误。

这是我的 python.conf 文件,位于 Fedora 7

LoadModule python_module module/mod_python.so

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath "['/var/www/vhosts/mysite.com/httpdocs','/var/www/vhosts/mysite.com/httpdocs/mysite'] + sys.path"

中的 /etc/httpd/conf.d/ 中。所以我知道 /var/www/ 不是放置我的 django 项目的最佳位置,但我只是想将我正在进行的工作演示发送给我的客户,稍后我将更改位置。

例如。如果我访问 www.domain.com/mysite/,我会得到在 mysite.urls 中配置的索引视图。但我无法访问我的app.urls(www.domain.com/mysite/app/)和任何admin.urls。(www.domain.com/mysite/admin/)

这是mysite.urls:

urlpatterns =patterns ('',

url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
(r'^$', 'app.views.index'),
(r'^admin/', include(admin.site.urls)),
(r'^app/', include('mysite.app.urls')),
(r'^photologue/', include('photologue.urls')),

)

我还尝试使用 ''django.contrib.admin.urls' 更改 admin.site.urls ,但没有成功。我在 google 上搜索了很多来解决这个问题,并阅读了其他开发人员如何配置他们的 django 项目,但没有找到太多在子目录中部署 django 的信息。我在 INSTALLED_APPS 中启用了管理员,并且 settings.py 没问题。

如果您有任何指导或告诉我我做错了什么,我将不胜感激。

谢谢。

HI guys. I was trying to configure my django project in a subdirectory of the root, but didn't get things working.(LOcally it works perfect). I followed the django official django documentarion to deploy a project with mod_python. The real problem is that I am getting "Page not found" errors, whenever I try to go to the admin or any view of my apps.

Here is my python.conf file located in /etc/httpd/conf.d/ in Fedora 7

LoadModule python_module modules/mod_python.so

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath "['/var/www/vhosts/mysite.com/httpdocs','/var/www/vhosts/mysite.com/httpdocs/mysite'] + sys.path"

I know /var/www/ is not the best place to put my django project, but I just want to send a demo of my work in progress to my customer, later I will change the location.

For example. If I go to www.domain.com/mysite/ I get the index view I configured in mysite.urls. But I cannot access to my app.urls (www.domain.com/mysite/app/) and any of the admin.urls.(www.domain.com/mysite/admin/)

Here is mysite.urls:

urlpatterns = patterns('',

url(r'^admin/password_reset/

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

, 'django.contrib.auth.views.password_reset', name='password_reset'), (r'^password_reset/done/

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

, 'django.contrib.auth.views.password_reset_done'), (r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

, 'django.contrib.auth.views.password_reset_confirm'), (r'^reset/done/

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

, 'django.contrib.auth.views.password_reset_complete'), (r'^

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

, 'app.views.index'), (r'^admin/', include(admin.site.urls)), (r'^app/', include('mysite.app.urls')), (r'^photologue/', include('photologue.urls')),

)

I also tried changing admin.site.urls with ''django.contrib.admin.urls' , but it didn't worked. I googled a lot to solve this problem and read how other developers configure their django project, but didn't find too much information to deploy django in a subdirectory. I have the admin enabled in INSTALLED_APPS and the settings.py is ok.

Please if you have any guide or telling me what I am doing wrong it will be much appreciated.

THanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白首有我共你 2024-08-10 05:50:55

我正在使用 mod_wsgi,所以我不确定它是否都一样。但在我的 urls.py 中,我有:

(r'^admin/(.*)', admin.site.root),

在我的 Apache 配置中,我有:

Alias /admin/media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media

您的路径可能会有所不同。

I'm using mod_wsgi, so I'm not sure if it's all the same. But in my urls.py, I have:

(r'^admin/(.*)', admin.site.root),

In my Apache config, I have this:

Alias /admin/media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media

Your path may vary.

梦年海沫深 2024-08-10 05:50:55

如果你的settings.py是正确的并且有正确的INSTALLED_APPS并且它在开发服务器中工作,那么我会说这是你的Apache配置文件。

尝试运行我的 python 应用程序来为 mod_python + Django 创建 Apache 配置文件。来源位于 github.com 的此处。一旦有了可用的配置文件,您就可以对其进行修改。

像这样运行:

C:\Users\hughdbrown\Documents\django\Apache-conf>python http_conf_gen.py --flavor=mod_python --source_dir=. --server_name=foo.com --project_name=foo
Writing 'foo.vhost.python.conf'

结果如下:

# apache_template.txt
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName foo.com

    DocumentRoot "./foo/"

    <Location "/">
        # without this, you'll get 403 permission errors
        # Apache - "Client denied by server configuration" 
        allow from all

        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonOption django.root /foo

        PythonDebug On
        PythonPath "[os.path.normpath(s) for s in (r'.', r'C:\Python26\lib\site-packages\django') ] + sys.path"
        SetEnv DJANGO_SETTINGS_MODULE foo.settings
        PythonAutoReload Off
    </Location>

    <Location "/media" >
        SetHandler None
        allow from all
    </Location>

    <Location "/site-media" >
        SetHandler None
        allow from all
    </Location>

    <LocationMatch "\.(jpg|gif|png)$">
        SetHandler None
        allow from all
    </LocationMatch>
</VirtualHost>

If your settings.py is correct and has your correct INSTALLED_APPS and it works in the development server, then I'd say it's you Apache configuration file.

Try running my python app to create Apache configuration files for mod_python + Django. The source is here at github.com. Once you have a working configuration file, you can modify it.

Run like this:

C:\Users\hughdbrown\Documents\django\Apache-conf>python http_conf_gen.py --flavor=mod_python --source_dir=. --server_name=foo.com --project_name=foo
Writing 'foo.vhost.python.conf'

Result looks like this:

# apache_template.txt
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName foo.com

    DocumentRoot "./foo/"

    <Location "/">
        # without this, you'll get 403 permission errors
        # Apache - "Client denied by server configuration" 
        allow from all

        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        PythonOption django.root /foo

        PythonDebug On
        PythonPath "[os.path.normpath(s) for s in (r'.', r'C:\Python26\lib\site-packages\django') ] + sys.path"
        SetEnv DJANGO_SETTINGS_MODULE foo.settings
        PythonAutoReload Off
    </Location>

    <Location "/media" >
        SetHandler None
        allow from all
    </Location>

    <Location "/site-media" >
        SetHandler None
        allow from all
    </Location>

    <LocationMatch "\.(jpg|gif|png)$">
        SetHandler None
        allow from all
    </LocationMatch>
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文