I an new to Django and I wrote a program which should print a text in the browser page. I therefore wrote urls.py and views.py, but the browser only shows the welcome page ("The install worked successfully"). What can the mistake be?
CodePudding user response:
- Make sure to add your app to
setting.py
- You must have two
urls.py
; one is for project located in project folder (next tosetting.py
) and the second is inside the app.
You have to use both of them to navigate correctly.
If your app name is myappname
, then do the followings:
On the main urls.py
inside your project folder (next to setting.py
), add:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myappname.urls')),
]
On the urls.py
inside your app add:
from django.urls import path
from .views import someview
urlpatterns = [
path('', someview.as_view(), name='name-list'),
]