简体   繁体   中英

Apache22 not serving django1.8 static files

I have been trying to get Apache22 serve static files for my Django1.8 application. I got mod_wsgi working to serve my application; however, once it does the css and js files are not present.

This is my settings static items:

STATIC_URL = '/static/'

STATIC_ROOT = 'C:/Users/name/Documents/app/DRF/app/static'

STATICFILES_DIRS = (
    ('assets', 'C:/Users/name/Documents/app/DRF/app/public'),
)

This is what I have in my Apache config file:

<VirtualHost *:80>
    Alias /static​​/assets/ "C:/Users/name/Documents/app/DRF/app/public"
    <Directory  "C:/Users/name/Documents/app/DRF/app/public">
        Order deny,allow
        Allow from all
     </Directory>

     #WSGIScriptAlias...
     #....more
</VirtualHost>

And in my template I have :

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static "assets/css/style.css" %}"></script>

When I manually go to the URL, 127.0.0.1/static/assets/css/style.css it just serves the default HTML page. Almost as if it cannot find the the route for that CSS file so it serves the default page again.

Any help is appreciated, thanks in advance.

Try changing:

Alias /static​​/assets/ "C:/Users/name/Documents/app/DRF/app/public"

to:

Alias /static​​/assets/ "C:/Users/name/Documents/app/DRF/app/public/"

You must match the trailing slash on URL and file path if you are going to add a slash.

So, either on both, or not on either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM