When I go to www.keithirwin.us, my site works fine. But when I go to keithirwin.us without the prefix, I get a django 404 error ("Page not found at /").
Now since I get a django error and not my browser's "server not found" error, it must at least be pointing to my server. But the django error says "You're seeing this page because debug = True" and that's false! So who's django project is it?
This problem has really twisted my brain. I'm just about ready to call an exorcist.
Aha! The DEBUG = True was from mezzanine's local_settings.py. I still don't know why I'm getting a 404 but I can figure it out from here.
Related
In my django app, I have multiple places where I raise a specific custom exception DeserializationError. My goal is to show/redirect to a pretty page to show the user this error, including the error message, when this error is raised. Basically, a page that says something like
Something went wrong. Please contact webmaster#email.com.
Error: DeserializationError. Message: SomeModel, "somemodel", does not exist.
Would this even be possible? I've been trying to search for a solution but haven't been able to find anything yet.
Most likely such errors will return HTTP 500 server error.
In django you can write your own custom view to handle such cases and return your own page with the html that you like.
The 500 (server error) view explains writing server error views. There are more types of errors handled as explained on same page.
An option for handling HTTP 500 errors, add this to your Settings file,
handler500 = 'mysite.views.my_custom_error_view'
and in the view, you can render the "error page" using
HttpResponseNotFound('<h1>Page not found</h1>')
the server_error() view will be overridden by handler500.
I am new to django. I am trying to serve downloadable files using django FileWrapper. But, I keep getting internal server error messages.
EDIT: My settings.py
DEBUG=True
link in html:
abcd.com/downloadResult/fileName/
My urls.py
url(r'^downloadResult/(\w{0,50})/$',"myApp.views.showResult",name="Result"),
My views.py
from django.core.servers.basehttp import FileWrapper
def showResult(request,fileName):
file=open("/path/to/file/"+fileName+".txt","r")
response=HttpResponse(FileWrapper(file),mimetype='application/force-download')
response['Content-Disposition']='attachment; filename=%s' % smart_str(fileName+".txt")
file.close()
return response
Can someone please direct me to some discussions or point out what I am missing?
Thanks!
I figured out the problem with my code. I closed the file before I return anything. After commenting out the second last line in views.py, it works fine. I found the error message in apache log file but did not get any error message in the browser even though DEBUG was set to True.
Now, the problem with this solution is that, there are files that are opened but never closed.
In my Flask app, I set up a 404 handler like this:
#app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
However, when a user goes to an unrecognized URL, the system gives an internal server error instead of rendering my 404 template. Am I missing something?
Internal Server Error is HTTP error 500 rather than 404 and you haven't added error handler for it. This occurs when the server is unable to fulfill the client request properly. To add a gracious message when such error occurred, you can add a errorhandler like 404.
#app.errorhandler(500)
def exception_handler(e):
return render_template('500.html'), 500
There is likely an issue while rendering the 404 template which then triggers an internal server error.
I suggest checking the logs for your app.
This will also occur if you have debug set to true. Try setting debug to false and see if your custom 404 shows up then.
i'm new to Python and Pylons and want to know how it is possible to cancle the start routin of the pylons app.
I found the middleware and want to do something like this:
if error:
abort(404)
But this brings me a 500 internal Server Error Message if error is true instead of a 404 Not Found Message.
Could anyone tell me how i can interupt start routin of pylons?
Try adding a message in the call:
abort(404,"404 Not Found");
As well, you can customize the error documents. See:
http://wiki.pylonshq.com/display/pylonsdocs/Error+Documents#changing-the-template
The problem is with the condition not abort.
Try this way:
def test(self):
username = ''
if not username:
abort(404)
How do I implement using python if I want to manage the 403 and 404 error, for example, to know which URL is most the 403 or 404 error?
There is no need to do this manually on App Engine. Just take a look at the "Errors" section in the dashboard for your app.
For more information on this, see http://code.google.com/intl/de-DE/appengine/kb/general.html#erroruris