Friday, 15 January 2010

python 2.7 - Simple Django redirection between two pages -



python 2.7 - Simple Django redirection between two pages -

newbie django , trying simple page redirection between index.html , error.html .

python manage.py runserver 0.0.0.0:8000 1.from views.py redirects localhost:8000\index (loads index.html expected) 2. when x button clicked js action performs xmlhttprequest() url:http://localhost:8000/myapp/transaction/ post phone call 3.from url.py (r'^myapp/transaction', transactionrequest) routed transactionrequest in views.py need perform action 4.currently returns simple json response string (responsestr = '{"status":'+str(invalid_cmd_code)+',"statustext":"'+invalid_cmd+'"}') 5.my js recieves reurn oject (till here works expected)

this point facing issues :

6. **with js homecoming object trying simple url redirection in js :: location.href="./errorpage/** 7. on django log comes errorpage definition(in views.py) when homecoming render_to_response('error.html') error page not loading please guide in solving django console log:

url.py

from django.conf.urls import patterns, include, url django.views.generic import redirectview myapp.views import transactionrequest,startthreads myapp.views import hello myapp.views import home myapp.views import redirecthome myapp.views import errorpage myapp.views import cardreadpage myapp.palprocessthread import test urlpatterns = patterns('', #('^hello/$', hello), #(r'^error', errorpage), #('^static/*', hello), (r'^myapp/transaction', transactionrequest), (r'^myapp/err*', errorpage), #(r'^myapp/err*', redirectview.as_view(url='error.html'), name='error.html')), (r'^myapp/index*', home), ('$', redirecthome) )

views.py

def hello(request): print "heloo" homecoming httpresponse("hello world") #@csrf_exempt def home(request): #context_instance=requestcontext(request) #return httpresponse("hello world") print "home" #print request print "end home" homecoming render_to_response('index.html') #@csrf_exempt def redirecthome(request): print "redirect" homecoming httpresponseredirect("/myapp/index") #@csrf_exempt def cardreadpage(request): print "cardread page" homecoming object_list(request, template_name='error.html') #return render_to_response('cardreadpage.html') #@csrf_exempt def errorpage(request): print "errorpage" print request.method print "errorpagess" homecoming render_to_response('error.html') @csrf_exempt def transactionrequest(request): response = httpresponse() try: print socket print "start" response['access-control-allow-origin']="*" cmd=0 responsestr = '{"status":'+str(invalid_cmd_code)+',"statustext":"'+invalid_cmd+'"}' systemerror = '{"status":'+str(sys_error_code)+',"statustext":"'+sys_error+'"}' except: responsestr = '{"status":'+str(invalid_cmd_code)+',"statustext":"'+invalid_cmd+'"}' response.content = responsestr homecoming response

console output :

txn_start postmsg prepare postmsg waiting response end txn_start transactionrequest end [13/feb/2013 01:52:56] "post /myapp/transaction/ http/1.1" 200 35 ***errorpage ( werw expect re routing of error.html) /myapp/cardread/ errorpagess*** traceback (most recent phone call last): file "/usr/lib/python2.6/wsgiref/handlers.py", line 94, in run self.finish_response() file "/usr/lib/python2.6/wsgiref/handlers.py", line 135, in finish_response self.write(data) file "/usr/lib/python2.6/wsgiref/handlers.py", line 218, in write self.send_headers() file "/usr/lib/python2.6/wsgiref/handlers.py", line 274, in send_headers self.send_preamble() file "/usr/lib/python2.6/wsgiref/handlers.py", line 200, in send_preamble 'date: %s\r\n' % format_date_time(time.time()) file "/usr/lib/python2.6/socket.py", line 318, in write self.flush() file "/usr/lib/python2.6/socket.py", line 297, in flush self._sock.sendall(buffer(data, write_offset, buffer_size)) error: [errno 32] broken pipe ---------------------------------------- exception happened during processing of request ('127.0.0.1', 35306) traceback (most recent phone call last): file "/usr/lib/python2.6/socketserver.py", line 560, in process_request_thread self.finish_request(request, client_address) file "/usr/lib/python2.6/socketserver.py", line 322, in finish_request self.requesthandlerclass(request, client_address, self) file "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 139, in __init__ super(wsgirequesthandler, self).__init__(*args, **kwargs) file "/usr/lib/python2.6/socketserver.py", line 618, in __init__ self.finish() file "/usr/lib/python2.6/socketserver.py", line 661, in finish self.wfile.flush() file "/usr/lib/python2.6/socket.py", line 297, in flush self._sock.sendall(buffer(data, write_offset, buffer_size)) error: [errno 32] broken pipe ---------------------------------------- home end home [13/feb/2013 01:52:58] "get /myapp/index http/1.1" 200 2846

django python-2.7 django-views

No comments:

Post a Comment