Wednesday, December 24, 2014

Re: How to capture any incorrect typing of a url and pass it to a default page

Try adding the *args and **kwargs parameters

    def my_default_2(request, *args, **kwargs):
        ...

On Wed, Dec 24, 2014 at 1:15 PM, pythonista <software.by.python@gmail.com> wrote:
I want to code the urls.py such that if someone types in any garbage inn the browser the final line of the url router will grab the line and reroute it to some page(the home page) for example.

I added the following line of code to the bottom of the url  

url(r'^([a-zA-Z0-9\-\_]*)', views.my_default),   expecting that it would send it to my default view

So, it appears to be working and  not matching anything above that  url and falls all the way through, however I am getting any error

TypeError at /waitlist/dict

my_default() takes exactly 1 argument (2 given)


My view is very simple

def my_default_2(request):      context = RequestContext(request)      context_dict = {'boldmessage': "pass through from waitlist"}      return render_to_response('waitlist/home.html', context_dict, context)


So, it looks like it is getting to the view, but I am getting the error above.
Any suggestions as to why I am getting the argument error above.

Thanks


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/67d57b9e-6d36-4c17-aee0-1fef5db37d79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei0_7oRjor9JJP9RhqEGE8rb%3DPaLNYTeTo3Pu41-Y0M-sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment