I know that you use .htaccess in the document-root directory in standard Apache.
What if I use Django? Can someone give me step by step how to create a custom 404 page?
The default 404 handler calls 404.html . You could edit that if you don't need anything fancy or can override the 404 handler by setting the handler404 view -- more here
Related
Recently, I deployed a Django web app. However, when I'm accessing the admin page, I'm not getting the expected interface to add or remove a user from a certain group:
At the of inspecting the page, I'm receiving the following messages:
any idea about how to handle these errros?
Thanks!
Content Security Policies are usually controlled via middleware like django-csp. All the admin control JavaScript files are included as static files, no external libraries should be loaded, they should be on the same domain.
In order for CSP to allow to load these files, you need to add script-src 'self' (it's an alias for same-origin). Look inside settings.py for CSP_SCRIPT_SRC keyword and append 'self' (single quotation marks are required).
Note: if CSP headers are added not by Django, but by reverse proxy, like nginx, then you should look and fix configuration settings there.
I am using python-social-auth for Google authentication in my Django application. Can I override the python-social-auth URLs ? By default, it's http://mydomain/login/google-oauth2/ and I need to change the URL as part of my view (get request) ; which has the end-point as http://mydomain/login/.
The only way to override the URLs is to define your own ones pointing to the views and link it into your main urls.py file.
If what you are after for is to make /login automatically handle the Google auth backend, then you need to define a custom view for it that can call python-social-auth views to fire up the process.
I have a code that causes an exception (function called from template).
When DEBUG=True it correctly raises Exception.
But when DEBUG=False just blank page is displayed.
What should I do to disable such behavior?
If you want to show the Django debugging exception page in production, you shouldn't do this.
If you just want to create a custom error page, create a template called 500.html - this will be rendered instead of a blank page.
I am having a django python website in domain.com. I am having a blog in a folder called as fmblog inside my public html. I want to access blog by entering domain.com/blog.
My blog is situated in /home/user/public_html/fmblog
So, I have an alias in my virtualhost configuration like the following.
Alias /blog /home/user/public_html/fmblog/
My issue is that, I am getting the blog when I try to access www.domain.com/blog. I am getting a 404 error when I try to access http://domain.com/blog.
Why is this happening? I know this will be fixed if I redirect every non-www requests to www using a rewrite rule. But I dont want to use that as it have some bad effects in my django website. How can I make my blog live even on non-www queries?
You can make a redirect for the blog only, adding the rule to the .htaccess in the fmblog, above the #BEGIN WordPress line
I am getting ready to deploy my first Django application and am hitting a bit of a roadblock. My base template relies on me passing in the session object so that it can read out the currently logged in user's name. This isn't a problem when I control the code that is calling a template.
However, as part of getting this app ready to be deployed, I need to create a 404.html page. I extended my base template just like I've done with my other pages, but I don't see a way to pass in the session object so that I can utilize it. Is there a way to have Django call a custom method to render your 404 rather than just rendering your 404.html for you?
You need to override the default view handler for the 404 error. Here is the documentation on how to create your own custom 404 view function:
http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views
Define your own 404 handler. See Django URLs, specifically the part about handler404.