Static files not loading when debug is false

2012-09-09 Thread Karambir Singh Nain
I have a fairly simple django project having some views, templates and 
static files like  css and images. My settings file include : 

STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/karambir/Codes/projects/cdi/cdi/data',
)
TEMPLATE_DIRS = (
'/home/karambir/Codes/projects/cdi/cdi/templates'
)

So I serve static files with  {{ STATIC_URL }} in the templates. And it is 
working fine when DEBUG is TRUE but every static file breaks when debug is 
set to false. Then I tried with django admin, it was also broken. So I run 
a ./manage.py collectstatic command. And then admin css works fine but my 
own files still not. I saw in the url of the loaded html page and it shows 
correct url and it is not loading. 
How can I know what is the main problem. What changes takes place when 
debug is set to false?
(I'm running django1.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/-/fWCsL9PUI1EJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-09 Thread Jani Tiainen
I suppose that your frontend webserver is serving files from url /static/
from path that STATIC_ROOT points to?

On Sun, Sep 9, 2012 at 10:23 PM, Karambir Singh Nain wrote:

> I have a fairly simple django project having some views, templates and
> static files like  css and images. My settings file include :
>
> STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
> STATIC_URL = '/static/'
> STATICFILES_DIRS = (
> '/home/karambir/Codes/projects/cdi/cdi/data',
> )
> TEMPLATE_DIRS = (
> '/home/karambir/Codes/projects/cdi/cdi/templates'
> )
>
> So I serve static files with  {{ STATIC_URL }} in the templates. And it is
> working fine when DEBUG is TRUE but every static file breaks when debug is
> set to false. Then I tried with django admin, it was also broken. So I run
> a ./manage.py collectstatic command. And then admin css works fine but my
> own files still not. I saw in the url of the loaded html page and it shows
> correct url and it is not loading.
> How can I know what is the main problem. What changes takes place when
> debug is set to false?
> (I'm running django1.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/-/fWCsL9PUI1EJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-09 Thread Jani Tiainen
Also just a note, if you're using manage.py runserver without debug = TRUE
setting, static file serving is not taking place. you can use --insecure
option to mark that you really want to do staticfile serving still from
django.

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#django-admin-option---insecure


On Sun, Sep 9, 2012 at 11:30 PM, Jani Tiainen  wrote:

> I suppose that your frontend webserver is serving files from url /static/
> from path that STATIC_ROOT points to?
>
>
> On Sun, Sep 9, 2012 at 10:23 PM, Karambir Singh Nain 
> wrote:
>
>> I have a fairly simple django project having some views, templates and
>> static files like  css and images. My settings file include :
>>
>> STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
>> STATIC_URL = '/static/'
>> STATICFILES_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/data',
>> )
>> TEMPLATE_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/templates'
>> )
>>
>> So I serve static files with  {{ STATIC_URL }} in the templates. And it
>> is working fine when DEBUG is TRUE but every static file breaks when debug
>> is set to false. Then I tried with django admin, it was also broken. So I
>> run a ./manage.py collectstatic command. And then admin css works fine but
>> my own files still not. I saw in the url of the loaded html page and it
>> shows correct url and it is not loading.
>> How can I know what is the main problem. What changes takes place when
>> debug is set to false?
>> (I'm running django1.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/-/fWCsL9PUI1EJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>
>


-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-09 Thread Stephen Anto
Hi Singh,

I have configured static file for my projects as follows.
In settings.py

import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
MEDIA_URL = '/site_media/'

STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/";
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.
)

and urls.py

urlpatterns = patterns('',
# For static file serving in development. Deactivate in production
environment
(r'^site_media/(?P.*)$',
'django.views.static.serve',{'document_root': settings.MEDIA_ROOT }),

)

I believe it may help you..

On Mon, Sep 10, 2012 at 12:53 AM, Karambir Singh Nain
wrote:

> I have a fairly simple django project having some views, templates and
> static files like  css and images. My settings file include :
>
> STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
> STATIC_URL = '/static/'
> STATICFILES_DIRS = (
> '/home/karambir/Codes/projects/cdi/cdi/data',
> )
> TEMPLATE_DIRS = (
> '/home/karambir/Codes/projects/cdi/cdi/templates'
> )
>
> So I serve static files with  {{ STATIC_URL }} in the templates. And it is
> working fine when DEBUG is TRUE but every static file breaks when debug is
> set to false. Then I tried with django admin, it was also broken. So I run
> a ./manage.py collectstatic command. And then admin css works fine but my
> own files still not. I saw in the url of the loaded html page and it shows
> correct url and it is not loading.
> How can I know what is the main problem. What changes takes place when
> debug is set to false?
> (I'm running django1.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/-/fWCsL9PUI1EJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Thanks & Regards
Stephen S



Website: www.f2finterview.com
Blog:  blog.f2finterview.com
Tutorial:  tutorial.f2finterview.com
Group:www.charvigroups.com

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-10 Thread e.generalov
There is another case - tests. The TestCase forces DEBUG=False, therefore 
staticfiles application, included to the project in accordance with the 
documentation, works in the development server, but unexpectedly does't 
serve static in test scenarios. Why the serving static files in the 
development environment is associated with the debugging?

понедельник, 10 сентября 2012 г., 10:08:27 UTC+6 пользователь Stephen Anto 
написал:
>
> Hi Singh,
>
> I have configured static file for my projects as follows.
> In settings.py
>
> import os
> PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
> MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
> MEDIA_URL = '/site_media/'
>
> STATIC_ROOT = ''
>
> # URL prefix for static files.
> # Example: "http://media.lawrence.com/static/";
> 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.
> )
>
> and urls.py
>
> urlpatterns = patterns('',
> # For static file serving in development. Deactivate in production 
> environment
> (r'^site_media/(?P.*)$', 
> 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT }),
> 
> )
>
> I believe it may help you..
>
> On Mon, Sep 10, 2012 at 12:53 AM, Karambir Singh Nain 
> 
> > wrote:
>
>> I have a fairly simple django project having some views, templates and 
>> static files like  css and images. My settings file include : 
>>
>> STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
>> STATIC_URL = '/static/'
>> STATICFILES_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/data',
>> )
>> TEMPLATE_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/templates'
>> )
>>
>> So I serve static files with  {{ STATIC_URL }} in the templates. And it 
>> is working fine when DEBUG is TRUE but every static file breaks when debug 
>> is set to false. Then I tried with django admin, it was also broken. So I 
>> run a ./manage.py collectstatic command. And then admin css works fine but 
>> my own files still not. I saw in the url of the loaded html page and it 
>> shows correct url and it is not loading. 
>> How can I know what is the main problem. What changes takes place when 
>> debug is set to false?
>> (I'm running django1.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/-/fWCsL9PUI1EJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> Thanks & Regards
> Stephen S
>
>
>
> Website: www.f2finterview.com
> Blog:  blog.f2finterview.com
> Tutorial:  tutorial.f2finterview.com
> Group:www.charvigroups.com
>
> 

-- 
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/-/FzCaiG9odeMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-10 Thread Karambir Singh Nain
Yeah. during, debug=true, it is serving fine from static_root. But not when 
debug is false.

On Monday, September 10, 2012 2:01:03 AM UTC+5:30, Jani Tiainen wrote:
>
> I suppose that your frontend webserver is serving files from url /static/ 
> from path that STATIC_ROOT points to?
>
> On Sun, Sep 9, 2012 at 10:23 PM, Karambir Singh Nain 
> 
> > wrote:
>
>> I have a fairly simple django project having some views, templates and 
>> static files like  css and images. My settings file include : 
>>
>> STATIC_ROOT = '/home/karambir/Codes/projects/cdi/cdi/static'
>> STATIC_URL = '/static/'
>> STATICFILES_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/data',
>> )
>> TEMPLATE_DIRS = (
>> '/home/karambir/Codes/projects/cdi/cdi/templates'
>> )
>>
>> So I serve static files with  {{ STATIC_URL }} in the templates. And it 
>> is working fine when DEBUG is TRUE but every static file breaks when debug 
>> is set to false. Then I tried with django admin, it was also broken. So I 
>> run a ./manage.py collectstatic command. And then admin css works fine but 
>> my own files still not. I saw in the url of the loaded html page and it 
>> shows correct url and it is not loading. 
>> How can I know what is the main problem. What changes takes place when 
>> debug is set to false?
>> (I'm running django1.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/-/fWCsL9PUI1EJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>
>

-- 
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/-/W-IOauTb9dQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Static files not loading when debug is false

2012-09-10 Thread Jani Tiainen
As I put in my second post. Static serving is not working (by default) when
you turn debugging off unless you provide --insecure option on manage.py
runserver command. That is by design. Though with you should see improperly
configured exception raised if you try to use forcefully static serving
view (url is not even added when debug is false thus you should just see
404 errors if you use recommended staticfiles configuration pattern).

Read carefully implications of using staticfiles app and how it replaces
runserver command:

https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#runserver

HTH.

On Mon, Sep 10, 2012 at 3:57 PM, Karambir Singh Nain wrote:

> Yeah. during, debug=true, it is serving fine from static_root. But not
> when debug is false.
>
>
> On Monday, September 10, 2012 2:01:03 AM UTC+5:30, Jani Tiainen wrote:
>
>> I suppose that your frontend webserver is serving files from url /static/
>> from path that STATIC_ROOT points to?
>>
>> On Sun, Sep 9, 2012 at 10:23 PM, Karambir Singh Nain 
>> wrote:
>>
>>> I have a fairly simple django project having some views, templates and
>>> static files like  css and images. My settings file include :
>>>
>>> STATIC_ROOT = '/home/karambir/Codes/**projects/cdi/cdi/static'
>>> STATIC_URL = '/static/'
>>> STATICFILES_DIRS = (
>>> '/home/karambir/Codes/**projects/cdi/cdi/data',
>>> )
>>> TEMPLATE_DIRS = (
>>> '/home/karambir/Codes/**projects/cdi/cdi/templates'
>>> )
>>>
>>> So I serve static files with  {{ STATIC_URL }} in the templates. And it
>>> is working fine when DEBUG is TRUE but every static file breaks when debug
>>> is set to false. Then I tried with django admin, it was also broken. So I
>>> run a ./manage.py collectstatic command. And then admin css works fine but
>>> my own files still not. I saw in the url of the loaded html page and it
>>> shows correct url and it is not loading.
>>> How can I know what is the main problem. What changes takes place when
>>> debug is set to false?
>>> (I'm running django1.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/-/**fWCsL9PUI1EJ
>>> .
>>> To post to this group, send email to django...@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users...@**
>>> googlegroups.com.
>>>
>>> For more options, visit this group at http://groups.google.com/**
>>> group/django-users?hl=en
>>> .
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient before...
>>
>>  --
> 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/-/W-IOauTb9dQJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.