django-static

Static files won't load when out of debug in Django

ぃ、小莉子 提交于 2019-11-30 06:25:08
问题 I'm creating a Django project. I just tried taking the project out of debug, DEBUG = False and for some reason all my static files do not show up. They give an error code of 500. How do i fix this? some of settings.py: DEBUG = True TEMPLATE_DEBUG = DEBUG ... TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django

How to refer to static files in my css files?

被刻印的时光 ゝ 提交于 2019-11-29 10:36:47
问题 I have a reference inside my CSS file that refers to a static image: #logo { background: url('/static/logo.png') } This works just fine on my dev machine but not on my production environment since the url should be static.mydomain.com/logo.png. How do I dynamically change the css file according to the STATIC_URL in my settings file? 回答1: Use a relative path. Relative to the folder where the css file reside 回答2: You can move any CSS that contains static file paths to inline CSS, contained in

Django static files won't load

不打扰是莪最后的温柔 提交于 2019-11-28 21:31:04
i'm a Django newbie working on my first project and having a problem with static files. I have created a simple auth system using django.contrib.auth consisting of two templates: mysite/templates/index.html and mysite/templates/registration/login.html . I have global static content in mysite/static which I want to be able to access on all templates rendered by all apps. mysite/templates/index.html contains <img src="{{ STATIC_URL }}pics03.jpg"/> which renders as "static/pics03.jpg" and loads fine when I visit the url localhost:8000/ mysite/templates/registration/login.html contains <img src="{

Static files won't load when out of debug in Django

梦想与她 提交于 2019-11-28 18:23:27
I'm creating a Django project. I just tried taking the project out of debug, DEBUG = False and for some reason all my static files do not show up. They give an error code of 500. How do i fix this? some of settings.py: DEBUG = True TEMPLATE_DEBUG = DEBUG ... TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', 'django

{% load static %} and {% load staticfiles %}: which is preferred?

左心房为你撑大大i 提交于 2019-11-27 15:06:44
问题 I'm not sure what the difference is, it seems like both of them are working. I googled around, and seems like they are pretty much same thing. Just out of curiosity, which one do people use in the field? I read that but still don't know when to use which, and which one people in the field use. Mine works for both of them. At first I thought it's loading static folder but it works for staticfiles too... – 回答1: For the moment (Django 1.9 and earlier), {% load staticfiles %} loads the static

Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

我与影子孤独终老i 提交于 2019-11-26 14:08:49
What are the differences of these three static url? I am not sure if I am right, I am using the MEDIA_ROOT to store my uploaded photos (via models.ImageField() ) However, I created a JS script to my admin and in admin.py . I defined the media as below: .... class Media: js = ('/admin/custom.js', ) and my settings.py : .... STATIC_ROOT = "/home/user/project/django1/top/listing/static" and I added the custom.js to STATIC_ROOT/admin/custom.js , but it is not working. Throwing 404 not found error. And then I change the STATIC_ROOT to STATICFILES_DIRS , and it works!! .... STATICFILES_DIRS = "/home

Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

故事扮演 提交于 2019-11-26 03:48:47
问题 What are the differences of these three static url? I am not sure if I am right, I am using the MEDIA_ROOT to store my uploaded photos (via models.ImageField() ) However, I created a JS script to my admin and in admin.py . I defined the media as below: .... class Media: js = (\'/admin/custom.js\', ) and my settings.py : .... STATIC_ROOT = \"/home/user/project/django1/top/listing/static\" and I added the custom.js to STATIC_ROOT/admin/custom.js , but it is not working. Throwing 404 not found