python - Django - template not loading, perpetual 302 message -


i getting following on command line when server running , navigate http://127.0.0.1:8000/terms:

[19/jun/2015 18:09:04]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:05]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:05]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:06]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:07]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:07]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:08]"get /terms http/1.1" 302 0 [19/jun/2015 18:09:08]"get /terms http/1.1" 302 0 

this kind of output continues perpetually until quit/exit server session manually.

i not sure why happening. pretty new django maybe overlooked obvious.

here terms view in views.py:

def terms(request):     if request.method == 'get':         return redirect(terms) 

this route terms in urls.py:

url(r'^terms/', 'my_app.views.terms'), 

i have created terms.html template in templates folder dummy text.

why not working?

i know there simpler ways want know why particular way doesn't work. trying understand how put conditional statements in views use requests library more complicated things have later on in project.

what misunderstanding?

the http status code 302 redirects. appear redirecting terms terms , creating infinite loop.

do mean redirecting? if so, mean redirecting to?

you can redirect object:

def my_view(request):     ...     object = mymodel.objects.get(...)     return redirect(object) 

or view:

def my_view(request):     ...     return redirect('some-view-name', foo='bar') 

or relative url:

def my_view(request):     ...     return redirect('/some/url/') 

or absolute url:

def my_view(request):     ...     return redirect('http://example.com/') 

check out redirect docs more info.

if didn't mean redirect, want return 1 of following: httpresponse(), render(), or render_to_response(). sure specify template (terms.html) within in view these.

for less work, use class-based views.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -