Muhammad Taqi
Muhammad Taqi

Reputation: 5424

Django Url not matching Page no found

i have a url that is

http://127.0.0.1:8000/users/profiles/?profile=17320

I have this line define in my urls.py file.

url(r'^profiles/(?P<profile>\d+)/$', views.display_profile),

and on running, and hitting the above url, it didn't open the page, infact display all available urls list. and also Page not found (404)

Upvotes: 2

Views: 1290

Answers (3)

Thomas Gak-Deluen
Thomas Gak-Deluen

Reputation: 2981

Your url matches something similar to this

127.0.0.1:8000/profiles/542/

if you want to use the profile id as a GET parameter instead change your urls to match

url(r'^profiles/$', views.display_profile),

And inside your view function or inside a class based view inside the get(self, request, *args, **kwargs) method get your parameter using

profile_id = request.GET.get('profile', None)      # where None is the value to use
                                                   # if profile does not exist

I hope this helps

I wrote another answer earlier answering your exact same question

How to access url part in python django?

Upvotes: 2

Kishor Pawar
Kishor Pawar

Reputation: 3526

Man there is difference in query string and url part as the param.
What you are doing is query string, and you have set up your url pattern for part of the url as param.
So your url should be like http://127.0.0.1:8000/users/profiles/17320/

Read more at URL Dispatcher

Upvotes: 1

dbf
dbf

Reputation: 6499

your regexp matches

http://127.0.0.1:8000/profiles/17320

not

http://127.0.0.1:8000/users/profiles/?profile=17320

so should be fixed. Also get params (like ?profile=..) are not captured in django urls.

Upvotes: 3

Related Questions