访问Apache提供的Django管理页面时出现权限错误

时间:2022-10-06 08:13:18

I am new to Django development and this site has been invaluable so far and I'm impressed with how much I've learned. That being said, I am running into a problem and I've been crawling through the related posts on this site yet can't seem to find anything that solves my issue.

我是Django开发的新手,到目前为止这个网站已经非常宝贵,我对我学到的东西印象深刻。话虽这么说,我遇到了一个问题,我一直在爬这个网站上的相关帖子,但似乎找不到任何解决我的问题的东西。

Here is what I've tried but no luck.

这是我尝试但没有运气。

So I am hoping that one of you might be able to take a look at what I'm doing and point me in the right direction. I am trying to get my Apache web server to serve up the CSS files for Django's admin page. But, when visiting: http://localhost/admin/, I get the error: Forbidden. You don't have permission to access /admin/ on this server.

所以我希望你们中的一个人能够看看我正在做的事情,并指出我正确的方向。我正在尝试让我的Apache Web服务器为Django的管理页面提供CSS文件。但是,访问时:http:// localhost / admin /,我收到错误:禁止。您无权访问此服务器上的/ admin /。

The CSS/JS for my site is located in mysite/static and the CSS/JS for the admin page is located in the Django installation folder, Django-1.5/django/contrib/admin/static/admin. Here are the relevant bits in my settings.py file:

我的网站的CSS / JS位于mysite / static中,管理页面的CSS / JS位于Django安装文件夹Django-1.5 / django / contrib / admin / static / admin中。以下是我的settings.py文件中的相关位:

STATIC_ROOT = '/home/me/Desktop/djcode/mysite/production_static'
STATIC_URL = '/static/'
STATIC_DIRS = (
    "/home/me/Django-1.5/django/contrib/admin/static/admin",
    "/home/me/Desktop/djcode/mysite/static",
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',

)

I've run the python manage.py collectstatic command which pulls all the necessary static files from my two directory locations and places them in a folder called production_static in my project folder.

我运行了python manage.py collectstatic命令,该命令从我的两个目录位置提取所有必需的静态文件,并将它们放在我的项目文件夹中名为production_static的文件夹中。

Here is the production_static folder layout:

这是production_static文件夹布局:

$ cd production_static
$ ls
admin css images img js

The admin folder contains all the static files needed for the admin page to display. But for some reason, the css folder contains both my site's CSS as well as the admin CSS. Same with the js folder. The images folder is my site's images and the img folder is the admin site's images. I don't know why the collectstatic command is making two copies of the admin's static files.

admin文件夹包含管理页面显示所需的所有静态文件。但由于某种原因,css文件夹包含我的网站的CSS以及管理员CSS。与js文件夹相同。 images文件夹是我网站的图片,img文件夹是管理网站的图片。我不知道为什么collectstatic命令正在制作管理员静态文件的两个副本。

Here is Apache's httpd.conf file:

这是Apache的httpd.conf文件:

AliasMatch ^/([^/]*\.css) /home/me/Desktop/djcode/mysite/production_static/css/$1
AliasMatch ^/([^/]*\.css) /home/me/Desktop/djcode/mysite/production_static/admin/css/$1

Alias /media/ /home/me/Desktop/djcode/mysite/media/
Alias /static/ /home/me/Desktop/djcode/mysite/production_static/
Alias /admin/ /home/me/Desktop/djcode/mysite/production_static/admin/

<Directory /home/me/Desktop/djcode/mysite/production_static>
Order deny,allow
Allow from all
</Directory>

<Directory /home/me/Desktop/djcode/mysite/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/me/Desktop/djcode/mysite/mysite/wsgi.py
WSGIPythonPath /home/me/Desktop/djcode/mysite    

<Directory /home/me/Desktop/djcode/mysite/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

I am making sure that I restart the Apache server every time I make changes to the httpd.conf file.

我确保每次更改httpd.conf文件时都重新启动Apache服务器。

And here is my urls.py file:

这是我的urls.py文件:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'mysite.views.homepage_view'),
    # other url-view mappings here
    url(r'^admin/', include(admin.site.urls)),
)

My homepage and other pages load fine. The CSS and JS are all wonderful. It's just when I try to access http://localhost/admin/ do I get a permissions error.

我的主页和其他页面加载正常。 CSS和JS都很精彩。就在我尝试访问http:// localhost / admin /时,我收到权限错误。

1 个解决方案

#1


1  

Get rid of this alias:

摆脱这个别名:

Alias /admin/ /home/me/Desktop/djcode/mysite/production_static/admin/

#1


1  

Get rid of this alias:

摆脱这个别名:

Alias /admin/ /home/me/Desktop/djcode/mysite/production_static/admin/