Issue
- I created a project, added main to it for the main page in views and
about, there are no errors, but the text is not displayed
nothing changes at startup, but on the main page it writes
maybe I'm missing something? setting ![settings](https://i.stack.imgur.com/2hkmx.png]
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls'))
]
setting.py
# Application definition
INSTALLED_APPS = [
'main',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
views.py in main app
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h4>Hellow i'm main page</h4>")
def about(request):
return HttpResponse('<h4>About as</h4>')
Urls.py in main app
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
path('about', views.about)
]
Solution
You forgot the trailing '/'. Don't worry it happened to me plenty of times when i started learning Django. It drove me crazy not knowing where the error was. :D
Urls.py in the main app
path('about/', views.about)
Not
path('about', views.about)
Answered By - Ahmed Mansy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.