Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

I currently have a template folder with 2 different HTML files (help.html and users.html).

I'm having issues accessing both pages with my current path setup:

mysite urls

from django.contrib import admin

from django.urls import include, path

urlpatterns = [

    path('help/', include('AppTwo.urls')),

    path('users/', include('AppTwo.urls')),

    path('admin/', admin.site.urls),

]

AppTwo urls

from django.urls import path

from . import views

urlpatterns = [

    path('', views.help, name='help'),

    path('', views.users, name='users'),

]

I know I'm missing something here as I am unable to generate views for both paths when I launch the server. The Django docs just seem to show examples of a single page or examples with variables.

1 Answer

0 votes
by (25.1k points)

Your both paths are referring in wrong way,

mysite urls.py

from django.contrib import admin

from django.urls import include, path

urlpatterns = [

   path('', include('AppTwo.urls')),

   path('admin/', admin.site.urls),

]

AppTwo urls.py,

from django.urls import path

from . import views

urlpatterns = [

    path('help/', views.help, name='help'),

    path('users/', views.users, name='users'),

]

In your question, you are adding different paths to include same app i.e. AppTwo.urls, which means your app two urls will start with either 127.0.0.1:8000/help/ or 127.0.0.1:8000/users/ and as in the app urls the path is blank so in both cases both views will refer to same path. Hence the url will fail.

In your project include your app.urls once and then in your app urls.py show the path for the views.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...