DEBUG = True still 500 error - python

I went into settings.py in the Django Framework for my site because I had run into a 500 Internal Server Error. I'd heard that this happens when DEBUG = False, however, my DEBUG is set to True and it still does not give me anything more specific than a 500 Internal Server Error.
My site was running perfectly fine and all of a sudden this error occurred...any thoughts?? I checked my wsgi link and nothing had changed there as well!

Related

Django Settings.py stuck on "SECURE_SSL_REDIRECT = True"

I added the setting
SECURE_SSL_REDIRECT = True
to my django settings.py. It works perfectly in production mode so no issues there however, now if I make it the following to test in development mode
SECURE_SSL_REDIRECT = False
I get the following error
You're accessing the development server over HTTPS, but it only supports HTTP.
What could the issue be? Seems like something is making it not register the new value.
Clearing browser cache helps.You can do that in the browser settings.

DisallowedHost at / Invalid HTTP_HOST header:

I am getting Error DisallowedHost at /
Invalid HTTP_HOST header: `'subdomain.example.com'`. You may need to add 'subdomain.example.com' to ALLOWED_HOSTS.
in my Django project which is deployed on IIS Windows server. Sometimes it works fine and sometimes it throws an error. Even I have set DEBUG = False. I got an error page as it appears in DEBUG = True mode.
Sometimes It works fine, and sometimes it throws an error. I have already added my subdomain i .e (subdomain.example.com) in ALLOWED HOSTS in settings.py.
Please help me to solve this problem permanently.
You need to set
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'yourdomain.com']
in the settings file, basically every domain you are going to run your web app from needs to be in this ALLOWED_HOSTS, I would suggest you to make a different settings file for development, production etc.

Django Deploying 500 status when debug=False

I'm using Django to build my own blog now and I think it's good. But now I've noticed a problem. When I change the DEBUG const to False, System checks are OK but It'll return a 500 error status. When I change it to True,The bug won't happen again. So what's the problem? Can anybody help me?

Django: Avoid showing error details in production

I am trying to make sure that my site is properly protected from showing the details of the error in production.
I've been struggling with this for a while, as at beginning I understood that in order to avoid Django from showing the error (module, line of code, etc.) all that was needed was changing DEBUG from True to False in settings.py.
However, I realized that Django was still showing error details, so investigating a bit more and I came to know that the following was also needed:
TEMPLATE_DEBUG = DEBUG in settings.py
404.html and 500.htmlinside the templates folder
Is there anything else needed to make sure that the user does not get those messages?
And how does Django deal with the other kind of errors, like 400? I saw here that there are handlers for 400 and 403, but I do not understand it and I don't know if they are needed at all for a basic using case.
If DEBUG is False, Django doesn't show error details to the user. If it did in your case, the most likely explanations are either that it's not using the settings.py file you think it's using (in which case you should check the Python path, the directory from which you run manage.py, and the value of DJANGO_SETTINGS_MODULE), or that you did not restart Gunicorn/uWSGI/Apache after you made the change to settings.py (Django does not restart itself automatically in production like it does in development).
As for 400 and 403, just leave the Django defaults. If Django receives a bad request (unlikely in production, because this will usually be caught by Apache or nginx), it will call bad_request() which will just show a "400 bad request" to the user. Likewise for other errors.

500 Internal Server Error Heroku

I have a little system built for learning purposes with Flask-SQLAlchemy and deployed on Heroku(python/postgresql:
http://monkey-me.herokuapp.com/
https://github.com/coolcatDev/monkey-me
My app works fine locally and I have unit tested its functionality and use cases through 14 successfully passed tests.
When I deploy everything seems to go perfectly. Its deployed, I define environment variable APP_SETTINGS>>>config.BaseConfig, I run the db_create.py script to initialize the db. I create some users:
username-userpassword:
Alex-passwordAlex
Jack-passwordJack
Sara-passwordSara
But one thing is missing...I go to the users page from the main navigation bar and I get a 5oo internal server error saying:
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
My app code on app.py has debug mode on:
if __name__ == '__main__':
app.run(debug=True)
But no further error is displayed.
Notice that if I access the system on heroku and I am logged out, if I go to Users I am as I should redirected to the login page so thats how far I have gone with the debug...
If I set the environment variable LAUNCHY_DEBUG on heroku to either true or false everything goes crazy and new problems appear...like I cant delete a user, the profile images wont load....
If I remove the LAUNCHY_DEBUG var from heroku the new problems(images wont load, can't remove user..) persist among the original 500 error of the users page.
Thanks in advance for any suggestion with the debugging
Use the following to get more feedback written in logs:
import logging
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)
That reveals the problem:
ProgrammingError: (ProgrammingError) column "user_bf.id" must appear in the GROUP BY clause or be used in an aggregate function
Modify query:
userList = (
users.query
.add_column(db.func.count(friendships.user_id).label("total"))
.add_column(user_bf.id.label("best_friend"))
.add_column(user_bf.userName.label("best_friend_name"))
.outerjoin(friendships, users.id == friendships.user_id)
.outerjoin(user_bf, users.best_friend)
.group_by(users.id, user_bf.id)
.order_by(test)
.paginate(page, 6, False)
)
Regarding the images disappearing:
Any file written on a filesystem hosted on heroku will be deleted on dynos end of lifecycle.

Categories

Resources