Why does HttpWebRequest throw an exception instead returning HttpStatusCode.NotFound?

Ya this can be quite annoying when web pages use status codes heavily and not all of them are errors. Which can make processing the body quite a pain. Personally I use this extension method for getting the response. public static class HttpWebResponseExt { public static HttpWebResponse GetResponseNoException(this HttpWebRequest req) { try { return (HttpWebResponse)req.GetResponse(); … Read more

How do you return 404 when resource is not found in Django REST Framework

Simply way to do it, you can use raise Http404, here is your views.py from django.http import Http404 from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView from yourapp.models import Snippet from yourapp.serializer import SnippetSerializer class SnippetDetailView(APIView): def get_object(self, pk): try: return Snippet.objects.get(pk=pk) except Snippet.DoesNotExist: raise Http404 def get(self, request, pk, format=None): … Read more

Django staticfiles app help

I implore you to read the howto docs here: http://docs.djangoproject.com/en/dev/howto/static-files/ In short: STATIC_ROOT is only used if you call the collectstatic manangement command. It’s not needed to add the directory to the STATICFILES_DIRS setting to serve your static files! During development (when the automatic serving view is used) staticfiles will automatically look for static files … Read more

IIS7 custom 404 not showing

answer was to use <httpErrors existingResponse=”Replace” errorMode=”Custom”> <remove statusCode=”404″ subStatusCode=”-1″ /> <error statusCode=”404″ prefixLanguageFilePath=”” path=”/pages/404.aspx?he” responseMode=”ExecuteURL” /> </httpErrors> and not to have any system.web customErrors this worked for both .aspx and non .aspx requests. bizarrely this combination did not come up in any of the blog posts and stackoverflow answers I had investigated, it was … Read more

Flask Application – How to link a javascript file to website

Ah yes, luckily I am currently developing a flask application at the moment. You are currently missing the static folder which by default flask looks into, a folder structure something like this: |FlaskApp —-|FlaskApp ——–|templates – html files are here ——–|static – css and javascript files are here Two important default folders that Flask will … Read more

Netlify renders 404 on page refresh (using React and react-router)

This was simple and it worked for me. I found this link https://create-react-app.dev/docs/deployment#netlify So as suggested by that link, I added a _redirects file inside the /public folder like /public/_redirects. I then pasted /* /index.html 200 into the _redirects file. I did all that in my VS Code, after which I pushed to github and … Read more