Re: Trouble with CSS/Static Files
On 5/04/2013 2:33pm, Vibhu Rishi wrote:
> Hi,Â
>
> >Have you ranÂ
> >$ manage.py collectstatic
>
> Can you explain why I need to do this on my dev machine when I am not
> deploying it to production ? If I look at the docs atÂ
> https://docs.djangoproject.com/en/dev/howto/static-files/#deployment ,
> it mentions that I need to run this to deploy it. However, the problem I
> was getting was on my local system.Â
What might help is to add some print statements in your settings.py
These are some of mine ...
import os
import sys
if 'runserver' in sys.argv:
DEBUG = True
# This gets the name of the directory above the settings.py directory
# which is necessary if you follow the Django 1.4 guidelines
APP_ROOT = os.path.split(os.path.realpath(os.path.dirname(__file__)))[0]
STATICFILES_DIRS = (
os.path.join(APP_ROOT, 'static/'),
os.path.join(APP_ROOT, 'app_a/static/'),
os.path.join(APP_ROOT, 'app_b/static/'),
os.path.join(APP_ROOT, 'app_b/static/'),
)
if DEBUG:
i = 0
for item in STATICFILES_DIRS:
i += 1
print('STATICFILES_DIRS#%s = %s' % (i, item ))
You will get a constant reminder of where things are and if compare that
output with the location indicated in the html page source, you will be
able to diagnose the problem fairly easily.
Hth
Mike
>
>
> Vibhu
>
>
> On Fri, Apr 5, 2013 at 4:00 AM, CJ Milholland <cjm1504@gmail.com
> <mailto:cjm1504@gmail.com>> wrote:
>
> Have you ranÂ
>
> $ manage.py collectstatic
>
> On Thursday, April 4, 2013 12:49:11 AM UTC-7, Vibhu Rishi wrote:
>
> I am not sure where I am going wrong, but the CSS files are just
> not getting picked up. I have just started a project and am
> using the dev server with the runserver command.Â
>
> Here's my relevant settings.py :Â
>
>
> STATIC_ROOT = os.path.join(os.path.dirname(____file__),'/static/')
> STATIC_URL = '/static/'
>
> My directory structure :Â
> .
> â"œâ"€â"€ homepage
> â"‚  â""â"€â"€ templates
> â"‚    â""â"€â"€ homepage
> â"œâ"€â"€ qj
> â""â"€â"€ static
>   â"œâ"€â"€ css
>   â"œâ"€â"€ img
>   â""â"€â"€ js
>
> qj is where my settings.py file is.Â
> static is where i have the css. I am using bootstrap css files.
> I want it to be at the top location as these files are going to
> be used in all the apps that i will be writing.
> homepage is where i have the index page that I am trying to link
> the css to. the html is as follows :Â
>
> $ cat homepage/templates/homepage/__index.htmlÂ
>
> <!DOCTYPE html>
> <html>
> Â <head>
> Â {% load static %}
> Â Â <title>Hello World!</title>
> <meta name="viewport" content="width=device-width,
> initial-scale=1.0">
> <!-- Bootstrap -->
> <link href="{% static 'css/bootstrap.min.css' %}"
> rel="stylesheet" media="screen">
> Â </head>
> Â <body>
> Â <h1>Hello World</h1>
> <script src="http://code.jquery.com/__jquery.js
> <http://code.jquery.com/jquery.js>"></script>
> Â Â <script src="static/js/bootstrap.min.__js"></script>
> Â </body>
> </html>
>
> I am trying both the {% static <url> %} and the hardcoded
> static/js to see if it is working. The following is the output i
> get on loading the / page:Â
>
> [04/Apr/2013 12:23:38] "GET / HTTP/1.1" 200 413
> [04/Apr/2013 12:23:38] "GET /static/css/bootstrap.min.css
> HTTP/1.1" *404* 1667
> [04/Apr/2013 12:23:38] "GET /static/js/bootstrap.min.js
> HTTP/1.1" *404* 1661
>
> It just is not picking up the css or the js file. What am I
> doing wrong ?Â
>
> Regards,
> Vibhu
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users%2Bunsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> Â
> Â
>
>
>
>
> --
> Simplicity is the ultimate sophistication. - Leonardo da Vinci
> Life is really simple, but we insist on making it complicated. - Confucius
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home