0

my urls.py code is,

path('case-studies/',views.CaseStudiesView.as_view(),name='case_studies'),

my views.py code is,

class CaseStudiesView(TemplateView):
     template_name = "caseStudies.html"

whenever I run my code I found the error as,

raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'case_studies'     not found. 'case_studies' is not a valid view function or pattern name.

Can anyone please help me to figure out the issue

  • Things to check: 1) You've run collectstatic again to gather the new files in STATIC_ROOT. 2) You've got DEBUG=False in your settings – SamSparx Aug 16 '22 at 20:24
  • The problem could be that your browser is using an old cache copy of the css files. Browsers typically assume that css files do not change often, and will only fetch css files once per day. – John Gordon Aug 16 '22 at 21:51
  • 1
    Does this answer your question? [What is a NoReverseMatch error, and how do I fix it?](https://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – Javad Aug 17 '22 at 08:31

1 Answers1

-1

Try running collectstatic command in the terminal and make sure that in settings.py, you have DEBUG=TRUE for DEBUG configuration.

Django only serves static files when in development , in production you will have to turn of debug to DEBUG=False and will need a service provider to serve static files to your project.

Javad
  • 2,033
  • 3
  • 13
  • 23
  • This answer is inaccurate and/or misleading. Django doesn't need a "service provider" to serve static content; see https://docs.djangoproject.com/en/4.1/howto/static-files/deployment/. You typically use a Apache (or similar) webserver to host your Django site, and the same webserver can host static pages. Besides, the OP appears to be asking about a templated page ... not static content. – Stephen C Aug 17 '22 at 09:04
  • the question has been edited but , when i tried to host my website on digital ocean it did not serve static – sameerAhmedjan Aug 17 '22 at 12:06
  • Neither the current or original version of the question mentions hosting the site on a 3rd-party web hosting site. Furthermore, the fact that you (apparently) can't host static content on Digital Ocean doesn't mean that is the same for all web hosting sites. It certainly wont be the case if you (say) installed and ran your Django instance + Apache in an AWS EC2 instance. In short, what you are saying is not correct **in general**. – Stephen C Aug 17 '22 at 12:45
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 19 '22 at 20:31