cookiecutter-django
cookiecutter-django copied to clipboard
/etc/host configuration docs needed
What happened?
This is a bug w/ the docs, I think there is a missing section about configuring the /etc/host file to allow for local connections through a url like my-dev-env.local. I asked the question on SO and the response allowed this to work for me.
Am I missing something here or is it necessary to update etc/host?
What should've happened instead?
Details about configuring the /etc/host file on the local machine to forward the request.
Try going to localhost:7000?
@Andrew-Chen-Wang thanks for the suggestion but your point doesn't seem to address the situation.
I am working through the documentation on "Running Locally with Docker" and unable to connect to my newly designated URL using nginx. I believe the problem is with the mapping between the URL and the 127.0.0.1. I am able to connect to the site through localhost:8000.
I updated my /etc/hosts with the following line:
127.0.0.1 my-dev-env.local
This has allowed me to connect to the site, though there are still issues.
- I was experiencing CSRF failures when attempting to login and sign up. I have had to include multiple security settings in my local settings, which I'm unsure if they are correct:
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
SESSION_COOKIE_SECURE = True
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
CSRF_COOKIE_SECURE = True
- I am able to submit the forms but every other page load results in a 404 error. I am unsure why this is happening.
I see. I'm working on a new PR after #2674. It's most likely because the original design for the Docker doc service was not properly configured. Try doing what that PR does; you can also try setting the DATABASE_URL to some db.sqlite. The problem is that Docker doesn't show an error; the doc service just won't work because Django.setup() fails and exits due to missing environment variables.
Is your nginx a Docker container in the same yml file? If so, then your server is located at django:5000 not localhost:5000. You'd need to make sure your Django app is not exposing port 5000 (you can add EXPOSE 5000 in your Dockerfile). Then your nginx app would actually need to be exposed as a port 80/443.
I'm not entirely sure why you're using nginx on your local development machine. Those settings are also coming from production.py... The CSRF settings implemented are fine. You must be using some kind of frontend framework or your nginx configuration is just incorrect. It'd be helpful to know:
- Is your nginx running in the Docker compose file?
- Are you running
docker-compose -f local.ymlorproduction.yml? - Did you try fixing the doc service according to that PR?
@Andrew-Chen-Wang I think we're talking about different things here. My issues are with the documentation and that it does not explain clearly how to run locally with HTTPS. I don't believe it's related to your PR.
- nginx (
jwilder/nginx-proxy:alpinespecifically) is being defined in the Docker compose file,local.yml - I'm running
docker-compose -f local.yml - This has nothing to do with the doc service
I'm following the documentation, where it's suggested to use nginx in local development to allow for testing with https (local.yml docs)
I've moved away from Docker at the moment but the problem remains, there should be a reference in Getting Up and Running Locally with Docker about updating one's /etc/host file to forward the request from my-dev-env.local to 127.0.0.1.
@coreygarvey Ah I see, sorry. Brain must've been no good when reading this (I think I read documentation and 127.0.0.1 and came up with a wrong conclusion by the time I finished reading).
Try adding your hostname to the ALLOWED_HOSTS setting in your settings.py:
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "my-dev-env.local"]
Edit: Also, I wouldn't suggest developing with HTTPS just because it's slow, especially paired with Django debug toolbar. The original PR mentioned how Facebook does it IIRC but in all honesty it's not necessary for a Django development server.
Ah reading the article the PR points too... I couldn't actually find anything about developers doing it. That article was written in 2013 for GENERAL users... The PR states that for social login, it requires the client to be in an HTTPS environment.. but I don't think that's necessary when you're using test keys for django-allauth.
This is a bug w/ the docs, I think there is a missing section about configuring the
/etc/hostfile to allow for local connections through a url likemy-dev-env.local.
You're correct, this is missing.
By default 127.0.0.1 is mapped to localhost. This can be verified by running $ host 127.0.0.1 or by checking /etc/hosts file, so would it not be easier to simply use localhost as the domain name for local dev?