Here is my setup:
localhost (Windows 11)
- Nginx
listening on port 80 and 443, 80 is NOT automatically redirected to 443
each proxy_passed to http://wsgi-server where wsgi-server=127.0.0.1:8080
- waitress_wsgi running as a service on port 8080
Here is Django config:
<!-- email_test.html -->
<!-- ... -->
<form action="{% url 'identity:email_test' %}" method="post">
{% csrf_token %}
{{ email_form }}
{% translate 'Send email' as submit_translated %}
<!-- I use django_bootstrap5 -->
{% bootstrap_button button_type="submit" content=submit_translated extra_classes='w-100'%}
</form>
# settings.py ----------
MIDDLEWARE = {
# ...
'django.middleware.csrf.CsrfViewMiddleware',
# ...
}
# forms.py -------------
class EmailTestForm(forms.Form):
email = forms.EmailField(
# help_text=password_validation.password_validators_help_text_html(),
label=_('Email'),
max_length=128,
)
# views.py -------------
def email_test(request):
context = {}
context.update(template_globals())
if request.method == "POST":
email_form = EmailTestForm(request.POST)
if email_form.is_valid():
email_obj = EmailMessage(subject='Hello', body='Email body',
from_email='[email protected]',
to=[email_form.cleaned_data.get('email')])
email_obj.send(fail_silently=False)
else:
email_form = EmailTestForm()
context['email_form'] = email_form
return render(request, "identity/email_test.html", context)
Here are my test resuts when I visit the URL on browser:
py manage.py runserver(default port 8000), browserhttp://127.0.0.1:8000, emptysettings.CSRF_TRUSTED_ORIGINS: Works fine.- Browser
http://localhostorhttp://127.0.0.1orhttps://localhostorhttps://127.0.0.1with individual entry not insettings.CSRF_TRUSTED_ORIGINS: CSRF error. - Browser
http://localhostorhttp://127.0.0.1orhttps://localhostorhttps://127.0.0.1with individual entry notsettings.CSRF_TRUSTED_ORIGINS: Works fine. - Browser
https://mymachine.netwith this entry inetc/hostsresolving to127.0.0.1and not insettings.CSRF_TRUSTED_ORIGINS: CSRF error. - Browser
https://mymachine.netwith this entry inetc/hostsresolving to127.0.0.1and insettings.CSRF_TRUSTED_ORIGINS: Works fine. - Browser
http://localhost:8080orhttp://localhostorhttp://mymachine.net:8080: Works fine.
Does this mean that for (2-5), since the actual server the Django app runs on is the WSGI server on port 8080, request forwarded from the web server is not considered same site?