Re: Static files not loading when debug is false
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: How to use URL namespaces in tests?
Unfortunately in my case, no templates are used. среда, 5 сентября 2012 г., 20:37:06 UTC+6 пользователь Natim написал: > > Ok it is quite easy, you are missing {% load url from future %} in your > template. > > Le jeudi 23 août 2012 09:25:54 UTC+2, e.generalov a écrit : >> >> Url patterns which provided by a django application should be >> addressedexternally in >> the form of "namespace:name". I guess it will be connected to the project as >> follows: >> >> project/urls.py >> >> urlpatterns = patterns('', >> url('^something/', include('django_something.urls', >> namespace='something'))) >> >> URL patterns module in the application looks like: >> >> django_something/urls.py >> >> urlpatterns = patterns('', >> url('^$', show, name='show')) >> >> and I write a test: >> >> django_something/tests.py >> >> class ShowViewTest(TestCase): >> urls = 'django_something.urls' >> >> def test_should_render_something_template(self): >> url = reverse('something:show') # !!! >> response = self.client.get(url) >> self.assertIn('something.html', set([t.name for t in >> response.templates])) >> >> This test failes with exception "django NoReverseMatch 'something' is not >> a registered namespace" . How can I specify namespace 'something' in >> this case? > > -- 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/-/pZrdA5ZTyoAJ. 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: with/include template pattern? seeking best practices
{% for e in some_list %} {% include "single_element.html" with element=e %} {% enfor %} I find myself writing things like this a lot in django templates > > {% for e in some_list %} > {% with e as element %} > {% include "single_element.html" %} > {% endwith %} > {% enfor %} > > This would be in a template which shows a lists of elements, with another > template that renders a single one. The template single_element.html uses > element locally. I find this encapsulates my templates well, especially > in making single_element.html far more reusable. > > I've been doing this for a while and wanted to know if there is a better > way I just don't know about. Also, I don't know the performance > implications of so many with/include calls. This list could be very long > (100s or 1000s). > > Thanks! > Ivan Kirigin > http://kirigin.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/-/lV9pUIZXyPoJ. 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.
How to use URL namespaces in tests?
Url patterns which provided by a django application should be addressedexternally in the form of "namespace:name". I guess it will be connected to the project as follows: project/urls.py urlpatterns = patterns('', url('^something/', include('django_something.urls', namespace='something'))) URL patterns module in the application looks like: django_something/urls.py urlpatterns = patterns('', url('^$', show, name='show')) and I write a test: django_something/tests.py class ShowViewTest(TestCase): urls = 'django_something.urls' def test_should_render_something_template(self): url = reverse('something:show') # !!! response = self.client.get(url) self.assertIn('something.html', set([t.name for t in response.templates])) This test failes with exception "django NoReverseMatch 'something' is not a registered namespace" . How can I specify namespace 'something' in this case? -- 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/-/gu-nerRvUugJ. 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: How to serve staticfiles with full URL for local development?
On 11 май, 01:54, doniyor <doniyor@googlemail.com> wrote: > if your problem is how to serve your static files, just create a folder > with name static in your main app, then put all of your static files and > and your STATIC_URL is /static/. Thanks. I found some more ways to get around the restrictions of the `staticfiles` due development. I can to execute the `collectstatic` command, to fill STATIC_ROOT, and serve it with external server (nginx, for example), or apply monkey patches at StaticFilesHandler to override some protected methods. ps: but why these restrictions are needed in the tool, which should assist in the development? > Am Samstag, 5. Mai 2012 15:34:47 UTC+2 schrieb e.generalov: > > > > > > > > > > > There was a snippet to display a content of response in browser during > > debugging http://miniblog.glezos.com/post/3388080372/tests-browser. > > > "One of the first issues you might face is seeing a style-less page. > > This happens becuase the test server isn’t really a web server, and > > you’re probably serving static files from something relative such as > > '/ > > site_media'. The solution is simple: Run a separate Django server and > > tweak your development-only static URL to something like: > > > STATIC_URL = 'http://localhost:8000/site_media/ > > " > > > but this doesn't works anymore, because django.contrib.staticfiles > > doesn't serve static when STATIC_URL contains full URL. > > > I found the node at > >https://docs.djangoproject.com/en/dev/howto/static-files/#serving-sta... > > : > > > "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. > > > Additionally, when using staticfiles_urlpatterns your STATIC_URL > > setting can't be empty or a full URL, such ashttp://static.example.com/.; > > > Is there a way to omit this limitation for local development? > > > (reposted from > > >http://groups.google.com/group/django-developers/browse_thread/thread... > > ) -- 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: How to serve staticfiles with full URL for local development?
On 6 май, 04:41, Reinout van Rees <rein...@vanrees.org> wrote: > On 05-05-12 15:34, e.generalov wrote: > > > There was a snippet to display a content of response in browser during > > debugginghttp://miniblog.glezos.com/post/3388080372/tests-browser . > > > "One of the first issues you might face is seeing a style-less page. > > This happens becuase the test server isn t really a web server, and > > you re probably serving static files from something relative such as > > '/ > > site_media'. The solution is simple: Run a separate Django server and > > tweak your development-only static URL to something like: > > > STATIC_URL = 'http://localhost:8000/site_media/ > > " > > > but this doesn't works anymore, because django.contrib.staticfiles > > doesn't serve static when STATIC_URL contains full URL. > > I don't have any problems with static stuff. The solution is probably > simply to not include any hostname. What I have (on the server and > locally on my development box): > > STATIC_URL = '/static_media/' In order for static files at the temporary saved page, become accessible to the browser, them urls must be a full. -- /tmp/pageXXX.html -- http://localhost:8080/static/img.png;> (this suggestion has discribed at the sinppet's page). > > In case it still doesn't work: you probably use something else than the > standard runserver. In that > case,https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#django... > applies. You have to add that to your urls.py. But normally, you don't > have to. I see the code at https://github.com/django/django/blob/master/django/contrib/staticfiles/handlers.py#L31 , and it looks like the STATIC_URL checking logic is hardcoded to the handler. When `django.contrib.staticfiles` is added to INSTALLED_APPS, it overrides the standard `runserver` command and use specialized WSGIHandler to serve static files. It is not possible to change any behavior of this handler with standard django's request handling tools (urls.py, middlewares, views), because handler works before them all. > > Reinout > > -- > Reinout van Rees http://reinout.vanrees.org/ > rein...@vanrees.org http://www.nelen-schuurmans.nl/ > "If you're not sure what to do, make something. -- Paul Graham" -- 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.
How to serve staticfiles with full URL for local development?
There was a snippet to display a content of response in browser during debugging http://miniblog.glezos.com/post/3388080372/tests-browser . "One of the first issues you might face is seeing a style-less page. This happens becuase the test server isn’t really a web server, and you’re probably serving static files from something relative such as '/ site_media'. The solution is simple: Run a separate Django server and tweak your development-only static URL to something like: STATIC_URL = 'http://localhost:8000/site_media/ " but this doesn't works anymore, because django.contrib.staticfiles doesn't serve static when STATIC_URL contains full URL. I found the node at https://docs.djangoproject.com/en/dev/howto/static-files/#serving-sta... : "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. Additionally, when using staticfiles_urlpatterns your STATIC_URL setting can't be empty or a full URL, such as http://static.example.com/.; Is there a way to omit this limitation for local development? (reposted from http://groups.google.com/group/django-developers/browse_thread/thread/2dcaab0939455308/c422ab645b335513#c422ab645b335513) -- 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.