0

I have changed my Apache 2.2's httpd.conf

#Serve static files
Alias /static/ "E:\Python\Django\carlsblog\static\"
<Directory "E:\Python\Django\carlsblog\static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>

#Start mod_wsgi as default handler
WSGIScriptAlias / "E:\Python\Django\carlsblog\django.wsgi"

<Directory "E:\Python\Django\carlsblog">
Allow from all
</Directory>

and my app can be successfully run, only the static files cannot be accessed, a 404 is thrown by Django

However, if I change this line

Alias /static/ "E:\Python\Django\carlsblog\static\"

into

Alias /static/ "E:\Python\Django\carlsblog\static"

the index page of the static folder can be seen, but the files cannot be reached. When I checked Apache's error log at this time, I found something like this:

File does not exist "E:\Python\Django\carlsblog\staticmy_static_file.txt"

it seems there's a "\" missing, anyone has an idea on fixing this?

CarlLee
  • 3,952
  • 5
  • 23
  • 33
  • This has nothing to do with Django and is an Apache issue: Django does not server static file in a production environnement, as stated in the documentation. Please change your title accordingly. – Bite code Jun 19 '11 at 11:56
  • This is not related to your question but if somebody from outside your server to access your Python code, you should remove this immidiatly as it is a huge security issue. – Bite code Jun 19 '11 at 11:58
  • @e-satis I've moved my django.wsgi into E:\Python\Django\carlsblog\apache and changed – CarlLee Jun 19 '11 at 12:03
  • Try not using backward slashes. Apache quite happily uses forward slashes on Windows. This saves the confusion of whether a backslash acts as an escape character in certain circumstances and not others. – Graham Dumpleton Jun 20 '11 at 00:12

2 Answers2

4

Try removing the trailing slash from the alias itself:

Alias /static "E:\Python\Django\carlsblog\static"

Update (2015): This answer is from 2011. Currently, it is considered a much better practice to use gunicorn + nginx to serve django apps.

Udi
  • 29,222
  • 9
  • 96
  • 129
  • In my sitation (windows) I did have to do a whack like so - Alias /static "D:/Tidal/static/" having reverse whacks didn't work. – whoisearth Aug 20 '14 at 16:24
0

Are your templates OK? Check your generated html using View Source in your browser.

Udi
  • 29,222
  • 9
  • 96
  • 129
  • It's nothing to do with my templates, I'm trying to get the static files directly to test if my config is right to serve static files – CarlLee Jun 19 '11 at 12:11