Home > Net >  Why I am getting Django page not found error?
Why I am getting Django page not found error?

Time:10-03

I am not understanding why I am getting this Page not found (404) Raised by:django.views.static.serve here is my code:

app views.py:

class SESmail(TemplateView):
      template_name = 'mail/account_confirmation.html'

app urls.py

urlpatterns = [
    path('confirmmail/',SESmail.as_view(), name='confirmmail'),

  ]

root urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
   #my others url....
    path('', include('sesmail.urls')),
    
] static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

settings.py:

INSTALLED_APPS = [ 
 ....
  'sesmail',
]


STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)

I am not understanding why I am getting this error? I added app name in my settings.py and also added url configuration properly in app urls.py and root urls.py. Where I am doing wrong?

CodePudding user response:

the error was happening because I commented my media root

#MEDIA_URL = '/media/'
#MEDIA_ROOT =  os.path.join(BASE_DIR, 'media')

After uncomment the problem is solved. if you are using static(settings.STATIC_URL, document_root=settings.STATIC_URL) in your root urls.py then you might be get this error again. Add settings.STATIC_ROOT instead of using settings.STATIC_URL

CodePudding user response:

Change your app urls.py into the following:

urlpatterns = [
    path('',SESmail.as_view(), name='confirmmail'),

  ]
  • Related