javascript - unable to print parameters from url -
i'm trying read 4 parameters js request django app. how i'm doing js request:
site = "http://127.0.0.1:8000/products/loginfo/" + account + "?userid=" + userid + "&sessionid=" + sessionid + "&url=" + url; httpget(site);
this url in urls.py:
url(r'^loginfo/(?p<siteid>[0-9])/(?p<userdid>)/(?p<sessionid>)/(?p<url>)/$', 'log_info', name='log_info'),
and view in views.py:
def log_info(request,siteid,userdid,sessionid,url): print 'siteid' + str(siteid) print 'userid ' + str(userid) print 'sessionid ' + str(sessionid) print 'url ' + str(url) return render_to_response("products/all.html", locals(), context_instance=requestcontext(request))
but, i'm nothing being printed on terminal, what's wrong?
the problem url pattern in url.py
doesn't match url entered.
you can use request.get
dictionary directly read query parameters.
for change url pattern as
url(r'^loginfo/(?p<siteid>[0-9]+)', 'log_info', name='log_info'),
^loginfo/(?p<siteid>[0-9]+)
matchesloginfo
followed number of digits.
this ensures if url has loginfo/1234
redirected log_info
, 1234
siteid
now change view as
def log_info(request,siteid): print 'siteid' + str( siteid ) # changes made here. print 'userid ' + request.get[userid] print 'sessionid ' + request.get[sessionid] print 'url ' + request.get[url] return render_to_response("products/all.html", locals(), context_instance=requestcontext(request))
Comments
Post a Comment