0

I am new to django and trying to build my first API.

The url structure is as follows but the problem is:

when the first part of the URL matches, it calls that one.

Ex. If I call 'welcome/example' it matches with welcome and doesn't make it to the actual welcome/example...

from django.conf.urls import include, url
from django.contrib import admin


urlpatterns = [
    url(r'^login/', include('shopify_app.urls')),
    url(r'^', include('home.urls'), name='root_path'),
    url(r'^admin/', admin.site.urls),
    url(r'^welcome/', views.welcome), 
    url(r'^welcome/example', views.create_example), #regex not working
]
1
  • 1
    your comment is wrong #regex not working, Here only regex cause you to not have your desired output. Its just matches with your first welcome url i.e. url start with string welcome, thats it , it matches and reditects to view Commented Oct 31, 2017 at 6:22

2 Answers 2

4

its better to use $ for exact match, so use this instead

url(r'^welcome/$', views.welcome), 
url(r'^welcome/example/$', views.create_example)

then go to /welcome/ and /welcome/example/

Sign up to request clarification or add additional context in comments.

Comments

0

Yes its better to use $ for exact match as answer given by @Exprator, if you don't want that, then you can shuffle your url's order as

url(r'^welcome/example', views.create_example)
url(r'^welcome/', views.welcome)

Its a good practice to include main URL at the end after sub urls, then you don't fall in this kind of issues

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.