I have a django project and in this project I have two apps: main and profiles.
So I added both mini apps to the settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'profiles',
]
and I can run the main application - if I go to:
http://127.0.0.1:8000/
It is running.
But If I go to:
http://127.0.0.1:8000/profiles
Then I get this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/profiles
Using the URLconf defined in schoolfruitnvwa.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
The current path, profiles, didn’t match any of these.
So my question is: how to tackle this?
Thank you
and my view.py file looks like this:
from django.shortcuts import render
from django.views import View
# Create your views here.
class CreateProfileView(View):
def get(self, request):
return render(request, "profiles/create_profile.html")
def post(self, request):
pass
and this is my urls.py file:
from django.urls import path
from . import views
urlpatterns = [
path("", views.CreateProfileView.as_view())
]
CodePudding user response:
Most likely you need to add an entry to the urls.py
file in your main app:
from django.urls import include, path
urlpatterns = [
# ...
path('profiles/', include('profiles.urls')),
# ...
]
This way, the urls.py
of your profiles app will be included. If you then define an entry path('', views.myview)
in this file, the overall url profiles/
will link to that view.
Details in the tutorial, which I highly recommend to work through from start to finish: https://docs.djangoproject.com/en/4.1/intro/tutorial01/#write-your-first-view