0

Not sure why this doesn't match any urls in urls.py. I checked with a regex checker and it should be correct.

urls.py:

url(r'^toggle_fave/\?post_id=(?P<post_id>\d+)$', 'core.views.toggle_fave', name="toggle_fave"),

sample url:

http://localhost:8000/toggle_fave/?post_id=7

Checked using this simple regex checked. Seems right. Any ideas?

Thanks!

1 Answer 1

4

the urlconf isn't used to match the request.GET parameters of your url. You do that within the view.

you either want your urls to look like this:

 http://localhost:8000/toggle_fave/7/

and match it using:

url(r'^toggle_fave/(?P<post_id>\d+)/$', 'core.views.toggle_fave', name="toggle_fave"),

with your view that looks like:

def toggle_fave(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    ...

or

http://localhost:8000/toggle_fave/?post_id=7

and your urls.py:

url(r'^toggle_fave/$', 'core.views.toggle_fave', name="toggle_fave"),

and views.py:

def toggle_fave(request):
    post_id = request.GET.get('post_id', '')
    if post_id:
        post = get_object_or_404(Post, pk=post_id)
    ...
Sign up to request clarification or add additional context in comments.

1 Comment

OK I understand, thank you. Though I think the regex part in urls.py is misleading then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.