django-staticfiles

Django 1.10 Templating/staticfiles not showing any images

寵の児 提交于 2019-12-12 01:56:30
问题 I am trying to enable Django templating in 1.10 and it is not behaving correctly. Anything I have referenced to be called from the static files (./manage.py collectstatic) is not showing where referenced in the html. I have it imported in my views: from django.shortcuts import render, render_to_response from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm from django.template import loader from django.contrib.auth.decorators import

Static files not being served from seperate django staticfile application

佐手、 提交于 2019-12-12 01:08:18
问题 I'm using webfaction to make a simple static website. I think I have done everything correctly, but still my static files (i.e css, images) are not being served. I used this guide to set things up: http://docs.webfaction.com/software/django/getting-started.html I did everything they told me to, so in brief: 1) made a separate static media application 2) updated settings.py 3) ran python manage.py collectstatic All of the above went pretty much according to plan and I can now see my static

Nginx Configuration with Static Files under Django

元气小坏坏 提交于 2019-12-11 18:26:30
问题 I am setting an Nginx configuration with my Django project. In order to provide some static file without /static/ showing on the URL, I add some rewrite rules in Nginx configuration. Here is part of my Nginx configuration: location /static/ { location ~* \.(png|jpg|jpeg|gif|css|js)$ { access_log off; expires 30d; } alias /path/to/myproject/static/; } location ~ ^/favicon.ico$ { rewrite ^/favicon.ico$ /static/favicon.ico; } location /foo/ { rewrite ^/foo/(.*)$ /static/abc/$1; } location /bar/

Why is {% load static %} a dependency for {% get_media_prefix %}?

。_饼干妹妹 提交于 2019-12-11 17:47:36
问题 I've been using {% get_media_prefix %} for a very long time. I was explaining this to someone when he pointed this out. Why do I need to declare {% load static %} in order to use it? It even uses in the documentation's example code here. To an extent I understand that static files and media files are similar in nature. Even when we use them with combination of nginx+gunicorn, nginx handles both of them(we let everything else proxy, but not these). But still we have a separate MEDIA_URL and

Django Nginx static file caching on browser

匆匆过客 提交于 2019-12-11 10:23:34
问题 I am trying to configure Nginx to leverage on static file caching on browser. My configuration file is as following server { listen 80; server_name localhost; client_max_body_size 4G; access_log /home/user/webapps/app_env/logs/nginx-access.log; error_log /home/user/webapps/app_env/logs/nginx-error.log; location /static/ { alias /home/user/webapps/app_env/static/; } location /media/ { alias /home/user/webapps/app_env/media/; } ... } When I add in the following caching configuration, the server

Django - ImageField, upload, store and serve image in development server

随声附和 提交于 2019-12-10 22:13:45
问题 I'd like to have an ImageField in the admin form for my model (say, for an individual's profile). And I'd like to display this image in a view later on. This is the model I have : class Individual(models.Model): ind_name = models.CharField(max_length=100) ind_photo = models.ImageField(default="default.jpg") def __str__(self): return self.ind_name This is what I have in the settings for my website : STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, "static") MEDIA_URL = '/static

Load Django “static” template tag library globally without explicitly loading it in every file

大城市里の小女人 提交于 2019-12-10 21:27:59
问题 I want to use the static tag in templates like so: <img src="{% static "img/test.jpg" %}"> I've found that that requires me to put {% load static %} at the beginning of every template file. Since I'm using it everywhere, I would like it to be a globally available tag so I don't need to put {% load static %} to use it. In my settings I do have: TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.static', ) I saw both of these questions: Make django static tag globally available and

Django not loading CSS?

▼魔方 西西 提交于 2019-12-10 19:49:37
问题 This is my urls.py import os.path site_media = os.path.join( os.path.dirname(__file__), 'site_media' ) urlpatterns = patterns('', url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': site_media }), ) My site_media folder and style.css file is in myProjectFolder/myApp/static/site_media/css/style.css and in my base.html template (all my other templates extend off of this base.html template) this is what I have: <head> <title>{% block title %}{% endblock %}</title>

How to serve django static files on heroku with gunicorn

谁说我不能喝 提交于 2019-12-10 17:41:09
问题 I have an app in Django, I deployed it on heroku but I am unable to serve static files on the server and below are my code and settings: settings.py DEBUG = True TEMPLATE_DEBUG = DEBUG import os PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) SITE_PATH = os.path.abspath(os.path.join(PROJECT_PATH, os.path.pardir)) STATIC_ROOT = '' STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(SITE_PATH, 'staticfiles'),) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders

django admin static files stopped working after upgrade to 1.4

牧云@^-^@ 提交于 2019-12-10 16:47:11
问题 Setting up static files in django has always been a nightmare to me. When it comes to dealing with django static content I get depressed and feel dumb and stupid. I never really cared about getting admin media files served as static ones since I barely use admin interface and there is no impact on performance. It has worked quite ok with this dev setup until I upgraded to 1.4 settings.py MEDIA_ROOT = 'd:/~Sasha/Portman/media/' MEDIA_URL = 'http://localhost:8000/media/' ADMIN_MEDIA_PREFIX = '