Home > Mobile >  Why doesn't Django does recognise an app?
Why doesn't Django does recognise an app?

Time:12-05

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:

  1. Make sure to add your app to setting.py
  2. You must have two urls.py; one is for project located in project folder (next to setting.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'),
    
]
  • Related