18π
server_name
must match hostname inlink
/script
URLs. Either declare your configuration as default for this interface:port pair (listen 8000 default
)- Nginx must listen on the interface where your hostβs IP is bound (seems ok in your case)
95π
I think using root
in location block is incorrect. I use alias
and it works fine, even without re-configuring django.
# django settings.py
MEDIA_URL = '/static/'
# nginx server config
server {
...
location /static {
autoindex on;
alias /opt/aa/webroot/;
}
}
Hope this makes things simpler.
- [Django]-Passing STATIC_URL to file javascript with django
- [Django]-Access Django model's fields using a string instead of dot syntax?
- [Django]-Error: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>
14π
I also struggled with this. However, following trick worked for me:
server {
listen 8000;
server_name localhost;
access_log /var/log/nginx/aa8000.access.log;
error_log /var/log/nginx/aa8000.error.log;
location / {
index index.html index.htm;
}
location ^/static/ {
autoindex on;
root /opt/aa/webroot/;
}
}
I just marked static as a regex with ^
and nginx started serving static files. No modification on Django side was needed.
- [Django]-"Too many SQL variables" error in django with sqlite3
- [Django]-How do i pass GET parameters using django urlresolvers reverse
- [Django]-How to copy InMemoryUploadedFile object to disk
5π
MEDIA_URL shall not be used to serve the Static content like js etc. Django provides a separate STATIC_URL settings option that can be used.
So this can be changed as
<script type="text/javascript" src="{{STATIC_URL}}js/jquery-1.3.2.min.js"></script>
Also, its more standard to use staticfile app templatetag like this:
{% load static from staticfiles %}
<script type="text/javascript" src="{% static 'js/jquery-1.3.2.min.js' %}"></script>
- [Django]-How do I drop a table from SQLite3 in DJango?
- [Django]-How do I change the range of the x-axis with datetime?
- [Django]-How to lookup django session for a particular user?
4π
Fim & Alexander β Thanks for the hints those helped.
Here is how I solved it for anyone stuck in the same boat β
settings.py β
>MEDIA_ROOT = ''
MEDIA_URL = 'http://x.x.x.x:8000/static/'
In my html β
<script type="text/javascript" src="{{MEDIA_URL}}js/jquery-1.3.2.min.js"></script>
In my views.py β
return render_to_response('templates/login-register.html', {},
context_instance=RequestContext(request));
nginx inside the sites-available config file β
listen x.x.x.x:8000;
server_name x.x.x.x.;
Restarted nginx
Restarted apache
- [Django]-How to disable Django's CSRF validation?
- [Django]-What is reverse()?
- [Django]-How to lookup django session for a particular user?