Hi,
I am not to interrupt your question, actually I have the same problems as you. It seems that Django comers suffer this problem so much. 1, Put your static files somewhere that staticfiles will find them
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"E:/code/python/djangoBook/django-testapp-develop/static" #this is only used in my local test
)
2, Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
)
2, Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
So I set that:
INSTALLED_APPS = (
# 'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.staticfiles', #this
'djangotoolbox',
'autoload',
'dbindexer',
'shape_practice',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static', #this
)
3, You'll probably need to refer to these files in your templates.
INSTALLED_APPS = (
# 'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.staticfiles', #this
'djangotoolbox',
'autoload',
'dbindexer',
'shape_practice',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static', #this
)
3, You'll probably need to refer to these files in your templates.
So I did this:
<img src="{{ STATIC_URL }}images/gauge_example.jpg" alt = "aa gauge example" width = "390" height = "225" />
And, so someone pointed out that : using RequestContext, so I dit that
def introduction(request):
t = loader.get_template('introduction.html')
c = RequestContext(request, {}) #this
return HttpResponse(t.render(c))
def introduction(request):
t = loader.get_template('introduction.html')
c = RequestContext(request, {}) #this
return HttpResponse(t.render(c))
The problem is that when I comment out "E:/code/python/djangoBook/django-testapp-develop/static" in the STATICFILES_DIRS , it has an error :
"NetworkError: 500 - http://127.0.0.1:8000/static/images/gauge_example.jpg". When I didn't commented out, it works. So I think STATICFILES_DIRS and STATIC_URL actually works in
my app, the problem is that how to set it to the correct path. In my case, I want to STATIC_URL can find my "static" folder which is in the project home directory.
I was puzzled by this problem many days, right now I have no way but to use local folder "E:/code/python/djangoBook/django-testapp-develop/static" to code and test in my PC.
Thanks.
Jianhui
On Sat, Jan 5, 2013 at 1:38 PM, Mārtiņš Jakubovičs <martins.jakubovics@gmail.com> wrote:
Hello.I try a lot of things and can't understand, why not working STATIC_ROOT and MEDIA_ROOT in settings.py.I want, that all my media and static folders is in different place that python files, so I set media, static and templates to different place. Templates TEMPLATE_DIRS works well, bet MEDIA_ROOT and STATIC_ROOT not.I try setup like this:/home/domain/www/my_proj/ there is project folder and all apps, and there I place my htdocs folder, in which is static, templates and media folders.When i set in STATIC_ROOT = '/home/domain/www/my_proj/htdocs/static'In apache error log i got:File does not exist: /home/domain/www/my_proj/my_proj/staticI don't get, why django don't want to take new setting...I use django 1.4.Thanks.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/crL9a25SIWMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment