These are chat archives for django/django

23rd
Dec 2016
Roel
@roelzkie15
Dec 23 2016 07:09

anyone can explain why i am getting IndexError: List assignment index out of range

Here is my code

    def create(self, request):
        heats = []
        idx = 0
        for item in request.data:
            animal = Animal(item['animal'])
            heat = Heat(item['heat'])
            heat.animal = animal

            heats[idx] = heat
            idx = idx + 1

Hope anyone can help.

Pami Ketolainen
@keto
Dec 23 2016 07:38
@badcoder28: you can't append to list like that. use heats.append(heat)
Himanshu Kumar
@himanshukumar660
Dec 23 2016 07:43
can anyone explain :- if urlpatterns = patterns(
'django.views.static',
(r'^media/(?P<path>.*)',
'serve',
{'document_root': settings.MEDIA_ROOT}), )
working of this code??
Pami Ketolainen
@keto
Dec 23 2016 07:48
I would guess that serves the static files under MEDIA_ROOT at url media/
Himanshu Kumar
@himanshukumar660
Dec 23 2016 07:49
@keto Got it.. Thanks
Pami Ketolainen
@keto
Dec 23 2016 07:53
@himanshukumar660: I'm guessing that is some older django versions but here's the related doc for latest https://docs.djangoproject.com/en/1.10/ref/contrib/staticfiles/#static-file-development-view
Himanshu Kumar
@himanshukumar660
Dec 23 2016 07:56
@keto yep, it is not supported in django 1.10, we just need to change that to : from django.views.static import serve urlpatterns = [ url(r'^media/(?P<path>)', serve, {'document_root':setting.MEDIA_ROOT}),]
Pami Ketolainen
@keto
Dec 23 2016 07:59
yeah, the urlpatterns format changed
also django.views.static and django.contrib.staticfiles.views seem to be slightly different things
Himanshu Kumar
@himanshukumar660
Dec 23 2016 08:04
Yep, django.contrib.staticfiles.views is used in production while django.views.static used in development and is inefficient and gross
Pami Ketolainen
@keto
Dec 23 2016 08:05
both have the big fat warning at the top of the module "Views and functions for serving static files. These are only to be used during development, and SHOULD NOT be used in a production setting."
in production you should serve your static files with ngingx or what ever you have in front of your django app
Himanshu Kumar
@himanshukumar660
Dec 23 2016 08:07
oh i get it
we should use some front end to avoid the overload to python process
Pami Ketolainen
@keto
Dec 23 2016 08:07
yep
Roel
@roelzkie15
Dec 23 2016 09:01
@keto yes thank you!
Antonis Christofides
@aptiko
Dec 23 2016 15:20
@himanshukumar660: You might also find this helpful: http://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/
Himanshu Kumar
@himanshukumar660
Dec 23 2016 16:57
@aptiko It was really helpful. Thank you
can anyone explain what is production script ?