After setting DEBUG = False, and SECURE_SSL_REDIRECT = True and deploying a version on my app to the server, I wish now to develop further locally. The problem is, I think at one point I forgot to remove the SECURE_SSL_REDIRECT = True from settings.py, and I ran the local dev server with heroku local. My local browser always tries not to connect to localhost with SSL, so it just hangs.
I tried removing the site-specific cookies for localhost in the browser settings (Chrome) but localhost now still always tries to establish an SSL connection.
I am trying just to get back to using a non-SSL local connection for development. Any Ideas?
Django version 1.10.2
Heroku
Thanks
EDIT
Seems if I clear ALL the cache and cookies and restart the browser then it will not ask for SSL again. So it seems to be a browser problem. Anyway if anyone has an idea of how to accomplish this without having to clear all the data in Chrome, that would be appreciated.
UPDATE
I have learned a better way to handle this situation. I have set up some code to automatically sense if the software is running on the local environment or the cloud production environment, like this:
if os.environ.get('LOCAL'):
DEBUG = True
SECURE_SSL_REDIRECT = False
else:
DEBUG = False
SECURE_SSL_REDIRECT = True
Of course you have to take care of setting up the environ object, which happens automatically in heroku.
I am using custom settings both for local (development) and production environments.
For instance:
myproject/settings/dev.py
DEBUG = True
SECURE_SSL_REDIRECT = False
...
myproject/settings/production.py
DEBUG = False
SECURE_SSL_REDIRECT = True
...
And then I specify the settings I want to use. On localhost like this:
python myproject/manage.py runserver --settings=settings.dev
and for production using the Heroku Procfile:
web: gunicorn myproject.wsgi.production --log-file -
Content of myproject/wsgi/production.py is:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings.production")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
If you use heroku local for your local development, you can create similar Procfile.local with local wsgi file.
Related
I'm trying to run my project in django in local without using https. I have added the following to the settings I'm using:
SECURE_SSL_REDIRECT = False
DEFAULT_HTTP_PROTOCOL = 'http'
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') (commented)
I'm running the serve with the following command: python3 manage.py 0.0.0.0:8000. If I browse to 0.0.0.0:8000, it works (it uses http). Nonetheless, if I use localhost:8000 then it always redirects to https and the following error appears:
I do not know if it helps, but I'm using django 1.11 version inside a docker container.
If you have set SECURE_SSL_REDIRECT to True once, and accessed localhost from browser, redirection happens and its stored in cache. Even if you revert SECURE_SSL_REDIRECT to False, you will observe the redirection. You can either check in incognito mode or clear browser cache.
Trying to access django server on localhost from my react native app. All I get is Network Error, which doesn't say much. Tried changing info.plist file as suggested in other answers on stack, tried changing firewall settings and so on.
The thing that worked and solved all my problems was changing the url on axios to my local ip and running django server with command: python manage.py runserver 0.0.0.0 which to my understanding will accept any connection to the server.
I use Django to send email,everything is OK when running on development environment, which uses command "python manage.py runserver 0.0.0.0:8100". But in the production environment which deployed by nginx+uwsgi+Django do not work.
Here is the code:
#Email settings
EMAIL_HOST='smtp.exmail.qq.com'
EMAIL_PORT='465'
EMAIL_HOST_USER='sender#qq.cn'
EMAIL_HOST_PASSWORD='password'
EMAIL_USE_SSL=True
RECEIVE_EMIAL_LIST=['receiver#qq.com']
send_mail('subject','content',setting.EMAIL_HOST_USER,setting.RECEIVE_EMIAL_LIST, fail_silently=False)
Have you checked that your production environment has the same network settings as the development environment?
Have you tried to ping or telnet the SMTP server from production?
Is possible that the production host is in a DMZ or in a subnet that has restricted access to the SMTP server you are trying to reach.
EMAIL_HOST = 'smtp.qq.com'
change EMAIL_PORT='465' to EMAIL_PORT = 587, with no quotes.
EMAIL_HOST_USER = 'abc#qq.com' # try to use your real email address.
RECEIVE_EMIAL_LIST=['receiver#qq.com'] to RECEIVE_EMIAL_LIST=['receiver#qq.com'**,**] # add a comma at the end of the list is a good habit.
I'm working on a Django app that's using the django-websocket-redis app to publish events from the server side.
I've successfully configured a test server using nginx and uWSGI to route both HTTP and WS requests correctly to my Django app, but on my local development environment I cannot get this working.
According to the django-websocket-redis documentation, it's enough to start the Django development server and everything should work fine, but it seems like this is far away from reality.
Here is what I've checked:
redis is running on localhost:6379 and is responding to PING requests
tried to run the server on different ports (80, 8080, 8000) to check if the django-websocket-redis makes any assumption about the development server's port, but nothing changed
searched for solution online, but there is nothing about this topic
On my local environment on the client side I see a 404 error when my app tries to connect to the local WebSocket. My settings.py sets the WEBSOCKET_URL to the correct URL (on test server it's working, but locally isn't).
Anyone has an idea what am I doing wrong? Thanks!
I've found a workaround to this.
I've modified my wsgi.py to this and it works now:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
from django.conf import settings
from ws4redis.django_runserver import WebsocketRunServer
if settings.DEBUG:
_django_app = get_wsgi_application()
_websocket_app = WebsocketRunServer()
def application(environ, start_response):
if environ.get('PATH_INFO').startswith(settings.WEBSOCKET_URL):
return _websocket_app(environ, start_response)
return _django_app(environ, start_response)
else:
application = get_wsgi_application()
UPDATE: it's not needed to create a custom management command as I mentioned previously, so I've deleted that part of the answer.
im writing a project using django.
while it was in a development stage i used DEBUG=TRUE, but now i want to upload it to heroku for production.
i set DEBUG=FALSE and kept getting an internal server error, so i further investigated and found that i need to set ALLOWED_HOSTS = ['localhost', '127.0.0.1'], so i did..
i ran it with the localhost but i still kept getting internal server error.
what am i doing wrong? cause i can't figure it out?
also, what should i put in allowed host for heroku site?
thanks
try this
python manage.py collectstatic
Remember that static files directory when debug = true is no the same when debug is false
heroku uses whitenoise for static files.
You need the domain you're accessing your server from in ALLOWED_HOSTS.
Example:
ALLOWED_HOSTS = ['www.example.com', ]
Yet, improperly configured ALLOWED_HOSTS should not result in internal server error responses (HTTP code 500) but in bad request responses (HTTP code 400).
Have you configured a way to log exceptions on your production server in order to investigate this?