python - Django REST tutorial DEBUG=FALSE error -
i'm trying learn use django rest framework via tutorial. i've gotten section "testing our first attempt @ web api".
when start server, get:
system check identified no issues (0 silenced). june 15, 2015 - 00:34:49 django version 1.8, using settings 'tutorial.settings' starting development server @ http://127.0.0.1:8000/ quit server control-c. [15/jun/2015 00:35:17]"get /snippets/ http/1.1" 500 74404
but when next step: /library/frameworks/python.framework/versions/3.3/bin/http http://127.0.0.1:8000/snippets/
i error says, among other things:
you're seeing error because have <code>debug = true</code> in django settings file. change <code>false</code>, , django display standard page generated handler status code.
so, when change settings.py say:
debug = false allowed_hosts = ['*']
and start server, happens: in first terminal window:
^$ python3 manage.py runserver performing system checks... system check identified no issues (0 silenced). june 15, 2015 - 00:52:29 django version 1.8, using settings 'tutorial.settings' starting development server @ http://127.0.0.1:8000/ quit server control-c.
then in second terminal window:
$ /library/frameworks/python.framework/versions/3.3/bin/http http://127.0.0.1:8000/snippets/ http/1.0 500 internal server error content-length: 59 content-type: text/plain date: mon, 15 jun 2015 00:52:42 gmt server: wsgiserver/0.2 cpython/3.3.5 server error occurred. please contact administrator.
and simultaneously, in first terminal window, bunch of stuff ending in:
file "/tutorial/tutorial/urls.py", line 9, in <module> url(r'^admin/', include(snippets.urls)), nameerror: name 'snippets' not defined
i don't understand how work. see @ least 1 person has asked similar question "debug=false" setting in context of own project, frankly answer on head. can please explain in context of tutorial?
many thanks!
this error:
file "/tutorial/tutorial/urls.py", line 9, in <module> url(r'^admin/', include(snippets.urls)), nameerror: name 'snippets' not defined
occurs because snippets.urls
has quoted. see example here:
urlpatterns = [ url(r'^', include('snippets.urls')), ]
as shown here, write this:
from django.contrib import admin urlpatterns = [ url(r'^polls/', include('polls.urls')), url(r'^admin/', include(admin.site.urls)), ]
note how second include() not contain quoted argument. that's allowable because import statement makes variable called admin
available , has attribute named site
, in turn has attribute named urls
; , whatever value of admin.site.urls
is, it's valid argument include() function.
but if write:
from django.contrib import admin urlpatterns = [ url(r'^polls/', include('polls.urls')), url(r'^admin/', include(snippets.urls)) ]
then python looks around variable named snippets, , because can't find one, python gives error:
nameerror: name 'snippets' not defined
...
you're seeing error because have
debug = true
in django settings file. changefalse
, , django display standard page generated handler status code.
in phrase will display standard page generated handler status code, status code means error code, means still error, not description of error. when in production mode, i.e. not development mode, don't want display error messages users have no idea mean, , in case have no means correct errors. so, in production mode set debug=false
.
however, when developing want verbose error messages display when goes wrong. otherwise, going see webpage says:
sorry went wrong: 500 error. goodbye.
which of absolutely no in tracking down error. leave debug=true
.
when start server, get:
system check identified no issues (0 silenced). june 15, 2015 - 00:34:49 django version 1.8, using settings 'tutorial.settings' starting development server @ http://127.0.0.1:8000/ quit server control-c. [15/jun/2015 00:35:17]"get /snippets/ http/1.1" 500 74404
you didn't have proceed further because last line there indicates error. status code of response request 500. if search google http status codes, learn 500 status code means went wrong on server side, , therefore server unable respond request, i.e. code has error in it.
Comments
Post a Comment