Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107062 > unrolled thread

Re: Static files load problem Django 1.9

Started byjustin walters <walters.justin01@gmail.com>
First post2016-04-15 08:24 -0700
Last post2016-04-15 08:24 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Static files load problem Django 1.9 justin walters <walters.justin01@gmail.com> - 2016-04-15 08:24 -0700

#107062 — Re: Static files load problem Django 1.9

Fromjustin walters <walters.justin01@gmail.com>
Date2016-04-15 08:24 -0700
SubjectRe: Static files load problem Django 1.9
Message-ID<mailman.29.1460733878.6324.python-list@python.org>
On Fri, Apr 15, 2016 at 5:13 AM, asimkon . <asimkostas@gmail.com> wrote:

> I have got a problem with static files regarding Django 1.9. These files
> are (js,css)  in the standard folder static, inside project folder
> directory. I got an error Http 404 that can not be loaded.
>
> Project folder / static / css / several files *.css
>                     /static / js / several files   *.js
>                      several_apps
>
> i have executed the python manage.py collectstatic
>
> settings.py
>
> STATIC_URL = '/static/'
>
> STATIC_ROOT = os.path.join(BASE_DIR, "static")
>
> STATICFILES_DIRS = (
>
>     os.path.join(BASE_DIR, 'static'),
> )
>
> and of course  as INSTALLED_APPS
>
> 'django.contrib.staticfiles',
>
> Sorry for my template (at the beginning of my work):
>
> {% load  staticfiles %}
>
> <html>
>     <head>
>         <link rel="stylesheet"  href="{% static 'css/jquery-ui.css' %}">
>         <link rel="stylesheet"  href="{% static 'css/ui.jqgrid.css' %}">
>         <script src="{% static 'js/jquery-1.11.0.min.js' %}"
> type="text/javascript"> </script>
>         <script src="{% static 'js/jquery.jqGrid.min.js' %}"
> type="text/javascript"> </script>
>         <script src="{% static 'js/grid.locale-el.js' %}"
> type="text/javascript"> </script>
>         <script src="{% static 'js/category.js' %}" type="text/javascript">
> </script>
>     </head>
>     <body>
>
>         <table id="grid"></table>
>         <div id="pager"></div>
>
>     </body>
> </html>
>
> but i am afraid the problem lies in urls.py (i do not know what to do)
>
> http://127.0.0.1:8000/static/css/file_name  (in the firebug  network) but
> i
> can not open it directly via server.
>
> urls.py
>
> urlpatterns = [
>     url(r'^admin/', admin.site.urls),
>     url(r'^hello/','category.views.hello'),
> ]
>
>
> Any kind of help would be convenient to me?
>
> Kind Regards
> Kostas Asimakopoulos
> --
> https://mail.python.org/mailman/listinfo/python-list
>


You shouldn't need a special pattern in your urls for static files.

I think your issue lies with your STATIC_ROOT setting. It is the same as
your STATICFILES_DIRS setting.

Try changing the STATIC_ROOT setting to:

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')

This will put the static root outside of your project folder. This may
solve your problem, and will make it easier to host static files somewhere
else on your server or in a CDN if need be.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web