Django admin static files 404 - python

I'm using Django version 1.10. Project work fine on Debug = True, but when I set it to False is not. Django just can't find static files.
My Django settings looks like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'master',
'update',
]
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
And the urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^master/', include('master.urls')),
url(r'^update/', include('update.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
uwsgi.ini file
[uwsgi]
chdir = %v
virtualenv = %v/py
module = go_conf.wsgi
master = true
http = :8000
vacuum = true
buffer_size = 64k
max-requests = 100
daemonize = %v/log.txt
I aslo used python manage.py collectstatic, and it collected everything but still not working.
I tried to solve this by reading other articles on this site, but nothing really worked for me.
Hope, that someone will at last help.

This is the Django desing. A quote from the docs for Static file development view:
This view will only work if DEBUG is True.
That’s because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.
If you are setting DEBUG=False you are probably going to make it production. If so, your static files must be served by a webserver (eg. Nginx, Apache etc).

check the whitenoice library,
it works great for development and production environment
Radically simplified static file serving for Python web apps

Related

Can not access admin on Heroku

So i pushed my Code to Heroku and I have a lot of trouble getting things to work. The Static files do not work, I installed WhiteNoise and so on but I break the site as soon as I use {%static 'js/whatever.js'%} but {% load staticfiles %} can be used without breaking the server. Currently my theory is that the admin won't load because of the static files but they are not required for the normal django admin right?
Here are my important lines I hope somebody finds the mistake.
settings.py
DEBUG = False
ALLOWED_HOSTS = [u'....herokuapp.com']
import dj_database_url
DATABASES ={'default':dj_database_url.parse('postgres://...jl4',conn_max_age=600)}
INSTALLED_APPS = [
'rest_framework',"rest_framework.authtoken",'django.contrib.admin','django.contrib.auth','django.contrib.staticfiles',]
AUTHENTICATION_BACKENDS =('django.contrib.auth.backends.ModelBackend',)
SITE_ID = 1
WSGI_APPLICATION = 'ABC.wsgi.application'
STATIC_URL = '/static/'
STATICFILES_DIRS =[os.path.join(BASE_DIR, 'static'), ]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
STATICFILES_STORAGE ='whitenoise.django.GzipManifestStaticFilesStorage'
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ABC.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
application.add_files('/ABC/static/', prefix='/static/')
Procfile file, requirements.txt, .git folder are present and look normal. I have no problems on 127.0.0.1 at all. No migration problems anywhere. Heroku is configured with a Python Buildpack and Postgres. 404 500 etc Handlers are installed and working (Btw I get a 500 Internal Server Error).
When I push the Code online with DEBUG=True (I know you should not do that but im totally frustrated), I have no Problems at all. Can Access the Admin and can Load the static files without any Problems.
So If anybody has an Idea whats missing please tell me. There are no stupid comments/questions I need answers!
from django.contrib import admin
from django.conf.urls import (
handler400, handler403, handler404, handler500
)
handler400 = 'my_profile.views.server_error'
handler403 = 'my_profile.views.server_error2'
handler404 = 'my_profile.views.server_error3'
handler500 = 'my_profile.views.server_error4'
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^my_profile/',include('my_profile.urls',namespace='my_profile')),
url(r'^login/',include('login.urls')),
url(r'^logout/',include('login.urls')),
url(r'^register/', include('registration.backends.simple.urls')),
url(r'^userprofile/',include('userprofile.urls')),
url(r'^about/',include('about.urls')),
url('^inbox/notifications/',include(notifications.urls,namespace='notifications')),

"TemplateDoesNotExist at /my_app_name" but Template-loader postmortem says "(File exists)"

I am getting the following error:
TemplateDoesNotExist at /app1/1/about/
index/index.html
but Template-loader postmortem says:
/var/www/web/sites/mysite.com/app1/templates/index/index.html (File exists)
I have tried all stackoverflow's answers on similar questions, but they didn't work for me. On my local server(running on OSX, virtualenv) everything is alright, but on production server I'm getting this error. On production server I'm using Django 1.7.5 on Ubuntu 14 with virtualenv.
Each app has it`s own template, the structure is like this:
app1
--templates
----index
------index.html
------head.html views.py app2
--templates
----index
------index.html
------head.html views.py
In settings.py I have the following parameters for templates:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DEBUG = True
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates'),]
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
INSTALLED_APPS = (
# django
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# widgets
'widget_tweaks',
'compressor',
'tinymce',
'django_activeurl',
'debug_toolbar',
# modules
'app1',
'app2',
)
and including them in views like this:
template_event = loader.get_template('index/materials.html', dirs=["app1/templates/"])
You have confused the template loader by passing in the dirs argument, which overrides whatever is in TEMPLATE_DIRS.
First, you don't need to set TEMPLATE_DIRS if all your templates are included inside app directories. The TEMPLATE_DIRS variable exists if you want to load templates from other file system locations. If all your templates are in app/templates/, then you don't need to set TEMPLATE_DIRS.
Since you are trying to load a template that is part of an application, simply pass the relative path to the template:
template_event = loader.get_template('index/materials.html')
Now, here is what django is gong to do (highly simplified):
First, it will look at TEMPLATE_LOADERS and then call each of the loader for its templates. The first loader is the file system loader, which will use the TEMPLATE_DIRS setting to find any templates. If a template here matches the path, then it will stop.
The next loader is the app_directories loader, this loader will look for a directory named templates in any app that is added to INSTALLED_APPS and then return the first template that matches.
The postmartem is telling you that the loaders have found your template, but the way you are asking them to load templates - they cannot find the template.
Just realized my mistake, after deep reading of django documentation, figured out that Alsadair was right with his answer in comments.
Usually, the recommendation is to put an app1 subdirectory i.e.
app1/templates/app1/, and load app1/index/materials.html. Then dirs is
unnecessary, in load_templates, and the template should be loaded from
the correct directory.

TemplateDoesNotExist at /polls/

I have been trying out the Django tutorialDjango Tutorial Page 3 and encountered this error
"TemplateDoesNotExist at /polls/ " .
I assume the problem is with my code pointing the templates file index.html. This is my file structure for index.html: mysite/polls/templates/polls.
I am copying my settings.py and views.py here.
settings.py
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
views. Py
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from polls.models import Poll
# Create your views here.
#def index(request):
#return HttpResponse("Hello, world. You are at the poll index.")
def index(request):
latest_poll_list = Poll.objects.order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = RequestContext(request, {
'latest_poll_list': latest_poll_list,
})
return HttpResponse(template.render(context))
def detail(request,poll_id):
return HttpResponse("You're looking at the results of the poll %s." % poll_id)
def results(request, poll_id):
return HttpResponse("You're looking at the results of poll %s." % poll_id)
def vote(request,poll_id):
return HttpResponse("You're voting on poll %s." % poll_id)
Can someone look into it and help me to solve this error. Any help would be appreciated.
This is the traceback `Environment:
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.6.4
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
C:\Python34\mysite\templates\polls\index.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
C:\Python34\lib\site-packages\django\contrib\admin\templates\polls\index.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\auth\templates\polls\index.html (File does not exist)
C:\Python34\mysite\polls\templates\polls\index.html (File does not exist)
Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\mysite\polls\views.py" in index
14. template = loader.get_template('polls/index.html')
File "C:\Python34\lib\site-packages\django\template\loader.py" in get_template
138. template, origin = find_template(template_name)
File "C:\Python34\lib\site-packages\django\template\loader.py" in find_template
131. raise TemplateDoesNotExist(name)
Exception Type: TemplateDoesNotExist at /polls/
Exception Value: polls/index.html`
Please let me know if i missed out anything that would give a more clear picture. Thanks in advance.
Settings.py """
Django settings for mysite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ma_x5+pnvp$o7#5g#lb)0g$sa5ln%k(z#wcahwib4dngbbe9^='
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'C://Python34/mysite/db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
#TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
Whoa whoa whoa. Let's not advocate non re-usability of apps.
For templates that don't fit anywhere else (usually your base template, maybe some partial templates like form includes, etc.), it's fine to put them in your root templates directory (ie. /path/to/project/templates/base.html). You would refer to them in a view for rendering as base.html.
For other templates, I would advise you put them in the directory of the app that contains the views that render to those templates. For example, your polls index would go somewhere such as /path/to/project/polls/templates/polls/index.html.
The extra polls directory may look redundant there, but the reason is that the django template loader will (logically) dump all your templates in one directory. So we use the second polls directory to differentiate between multiple index.html templates that may exist. So in your view, you would use polls/index.html as normal.
The reason that this is a Good Thing is that it makes your apps more easily reusable. Written one polls app? You've written them all. If you do this, and also keep your app specific static files (js, css, images, etc.) in your app's static directory, and have a urls.py for each app, generally all you will need to do to move your app from one project to another is copy the directory, add to the new project's INSTALLED_APPS, and include the urls from your base urls.py. And of course, modify the app in any way you need to for the new project.
It also means if you're using an editor with sidebar navigation (most of them, these days), you don't have to scroll all the way down to your templates to find the template for that app. When you start working on large projects this gets tedious, fast.
The only thing to remember in using this technique is that you must have django.template.loaders.app_directories.Loader in your TEMPLATE_LOADERS setting. This is the default so you usually won't have to worry about it.
There is a nice guide for this in the django docs: https://docs.djangoproject.com/en/1.7/intro/reusable-apps/
To answer the question you actually asked:
Your index.html should be here: C:\Python34\mysite\polls\templates\polls\index.html. If it isn't, that's what you're doing wrong.
On a related note, you probably shouldn't have your project in the Python directory.
Try to put template folder in projects root folder:
mysite/templates/polls/index.html
Explanation
Your template dirs is
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
It containts only one directory: /path/to/your/project/templates
And your index.html located in /path/to/your/project/polls/templates
Update
As you say it doesn't work with templates stored in mysite/templates/polls/index.html let's try this way:
go to mysite and run
python manage.py shell
to run interactive interpreter with mysite as context. Then run this:
from settings import TEMPLATE_DIRS
print TEMPLATE_DIRS
it will output something like
('/var/www/mithril/templates/', '/home/dmitry/proj/mithril/templates/')
Django uses this directories to find your templates.
Thus you should put directory polls/ in folder from TEMPLATE_DIRS.
You forgot to add your app config in the INSTALLED_APP in settings.py
INSTALLED_APPS = (
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
The startapp command creates an apps.py file. Since it doesn’t use default_app_config (a
discouraged API), you must specify the app config’s path, e.g. 'polls.apps.PollsConfig', in
INSTALLED_APPS for it to be used (instead of just 'polls').
I was having the same problem and I noticed there was another HTML file named index in site-packages. So I just changed my current HTML file to index1 and it worked.
Try to replace:
template = loader.get_template('polls/index.html')
with this:
template = loader.get_template('index.html')
Check if you forgot the 's' in
/polls/template
its
'/polls/templates' folder.
In your settings.py file, add this
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
And then in TEMPLATES DIRS, add this,
TEMPLATES = [
{
...
'DIRS': [TEMPLATE_DIR,],
...
},]
The issue is with your folder structure. Since you are inside the polls folder, you should have this template = loader.get_template('index.html') instead of template = loader.get_template('polls/index.html')
This is because of how the python path works, see here OS Path
You follow this structure,
mysite/
mysite/
templates/
polls/
index.html
there's something suspect to your TEMPLATE_DIRS path. It should point to the root of your template directory.
import os
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
...
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
In your error log django searching these paths,
C:\Python34\mysite\templates\polls\index.html
C:\Python34\mysite\polls\templates\polls\index.html
Make sure you didn't misspell detail.html as details.html. This was my problem.
you should have placed your templates inside poll app inside templates/polls/ structured. Such that the full path will look like mysite/polls/templates/polls/file.html
I had the same issue running through the tutorial. None of the above answers worked for me.
my solution:
make sure when you are saving your html files, click SAVE AS and then click the file type and click "All Files". My index.html file was actually index.html.txt and was not being found.

Django static files not loading with default setup

So I installed Bitnami Django stack, and enabled the admin module, and followed the tutorial for creating an admin menu for "Polls".
However, when I go to /admin/ everything is white plaintext. All the css and images are 404 error.
All I did was:
enable in settings.py installed_apps:
'django.contrib.admin',
In urls.py UNcommented:
from django.contrib import admin
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),
uncommented.
In settings.py, I tried using default settings and also tried this:
MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'static/'),
)
Nothing seems to work, it refuses to find static files in /admin/media/css/ etc.
I made sure my windows PATH has /bin of django. I even tried including /contrib, nothing helps.
I have installed Django to:
C:\DjangoStack\apps\django
I have installed my project to:
C:\Users\dexter\BitNami DjangoStack projects\Alpha
and I type: localhost/Alpha/admin to go to admin.
I almost missed the answer to this until I re-read your question and finally caught the bit in the last line: "and I type: localhost/Alpha/admin to go to admin". That means all your URL settings are wrong.
Currently, you have:
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
Whereas, these should be:
MEDIA_URL = '/Alpha/media/'
STATIC_URL = '/Alpha/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
Additionally, you don't need "static/" in STATICFILES_DIRS. So remove that setting.
I'm from the BitNami Team and I just saw this issue. I'm not sure if you are using and older version but at least in the newer version of the BitNami DjangoStack you just need to make sure that the ADMIN_MEDIA_PREFIX point to /static/admin/ if you are following the
instructions in https://docs.djangoproject.com/en/1.3/intro/tutorial02/ . You don't need to copy the static files in your project directory because django automatically will use the files in django/contrib directory.
However currently we are setting the ADMIN_MEDIA_PREFIX to /static/admin/media because the behavior is different when the application is served by Apache instead of the django server. We realize that this may be a bit confusing for users that are just starting with django and we are looking at this on our side to keep the default configuration for the new projects but also allow the demo project to be served by Apache.

How do I serve CSS to Django in development?

I've been all through the documentation, and it just doesn't make sense to me. I ran collectstatic, I set up /static/ directories in both my app and my project directories, I added STATIC_URL and STATIC_ROOT to my settings.py file (but I have no idea how to know if they're set correctly) and {{ STATIC_URL }} still isn't rendering out to anything. It all seems like a heck of a lot of overkill just to connect html to css.
I think I'm lost in the details; could anyone supply a high-level breakdown of this static files idea? I'm afraid I may have mixed instructions for both production and development setups.
MORE: Here's the relevant bit from my settings.py file:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django.contrib.staticfiles',
'dashboard.base',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'C:/Users/Sean/Desktop/Work Items/dashboard/base/static/',
)
And this is the code I'm trying to use in my template:
<link rel="stylesheet" href="{{ STATIC_URL }}css/960.css" />
OK. I made the changes everybody recommended. Here's my new urls.py:
from django.conf.urls.defaults import *
from base.views import show_project
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^dashboard/', include('dashboard.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
('^show_project/$', show_project),
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT, 'show_indexes': True }),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT, 'show_indexes': True }))
urlpatterns += staticfiles_urlpatterns()
Am I missing something? Usually my problems turn out to be something really basic that CS pros take for granted but I miss.
Here's how mine is setup. It sounds like you might be missing the static context processor?
STATIC_ROOT and STATIC_URL
In the settings.py used in development:
STATIC_ROOT = ''
STATIC_URL = '/static/'
And the settings.py used on my production server:
STATIC_URL = '//static.MYDOMAIN.com/'
STATIC_ROOT = '/home/USER/public_html/static.MYDOMAIN.com/'
So, all the static files are located in static/. On the production server, all these files in static/ are collected to /home/USER/public_html/static.MYDOMAIN.com/ where they are served by a different web server (nginx in my case) and not Django. In other words, my django application (running on Apache) never even receives requests for static assets in production.
CONTEXT PROCESSOR
In order for templates to have the STATIC_URL variable available to them, you need to use the django.core.context_processors.static context processor, also defined in settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
# other context processors....
'django.core.context_processors.static',
# other context processors....
)
SERVER STATIC ASSETS IN DEVELOPMENT
Django doesn't get requests for static assets in production, however, in development we just let Django serve our static content. We use staticfiles_urlpatterns in urls.py to tell Django to serve requests for static/*.
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# .... your url patterns are here ...
urlpatterns += staticfiles_urlpatterns()
Have a look at Serving static files in development. You need to define the STATIC_URL and STATICFILES_DIRS to let django.contrib.staticfiles know where to look for files.
The idea behind the static files idea is that you can distribute your development related media file (css/js etc.) on a per-app basis, and allow the static files application to manage and collect all these resources from their various places.
So you tell the static files app where to look for static files (by settings STATICFILES_DIRS), where to copy to them (STATIC_ROOT) and what path to access them (STATIC_URL). When you run collectstatic, it search through the directories and copies all the files it finds into the static root.
The benefit of this is that you can manage your static files on a finer leve:
project/app1/static/css/ # These are css/js for a particular app
project/app2/static/css/
project/app3/static/css/
project/static/css # These might be general css/js for the whole project
static/ # This is where the collectstatic command will copy files to
and after you collectstatic them you will have:
project/app1/static/css/
project/app2/static/css/
project/app3/static/css/
project/static/css
static/app1/css/
static/app2/css/
static/app3/css/
static/css/
When you put your app/site on a production server, you let the webserver (apache, nginx) deal with serving the files by telling it to serve media files at /static/ or /media/ directly, while passing all other requests to the application. When developing though, it's easier to let the development server do this for you.
To do this, you have explicitly tell is server any request for media under /static/ (your STATIC_URL). In your urls.py, put the following (or similar)
from django.conf import settings
...
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT, 'show_indexes': True }),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT, 'show_indexes': True }))
I have the same problem, and search many answers, but no one give me right answer.
The problem is you don't use RequestContext I think.
You should make a RequestContext as the parameter of Template like
c = RequestContext(request, {
'foo': 'bar',
})
In my views is:
return render_to_response('parts/test2.html', RequestContext(request, locals()))

Categories

Resources