Reputation: 11873
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.
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.
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:
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.
Here is the production_static
folder layout:
$ 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.
Here is Apache's httpd.conf
file:
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.
And here is my urls.py
file:
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.
Upvotes: 1
Views: 2090
Reputation: 14190
Get rid of this alias:
Alias /admin/ /home/me/Desktop/djcode/mysite/production_static/admin/
Upvotes: 1