Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name 'settings' is not defined

I add urls in these lines for media and image output to the template. But I meet such a bug. name 'settings' is not defined How do I fix it?

urlpatterns =+ patterns('',
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.STATIC_ROOT,
    }),
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.MEDIA_ROOT,
    }),
like image 302
wadadaaa Avatar asked Oct 02 '13 07:10

wadadaaa


2 Answers

Add

from django.conf import settings

to the top of your file. And change the operator used in urlpatterns variable assignment.

urlpatterns =+ patterns('',

should be

urlpatterns += patterns('',

There is no =+ operator in python.

EDIT:

From the urlpattern posted in comment, I see that there is no other urlpattern and the urlpattern should be as follows without the + sign.

urlpatterns = patterns('',
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT, }),
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }),
)
like image 165
arulmr Avatar answered Sep 25 '22 13:09

arulmr


Add

from django.conf import settings

To the top of your file.

like image 31
Burhan Khalid Avatar answered Sep 21 '22 13:09

Burhan Khalid