CSRF error appears when taking POST action in only MS Edge Browser(Chrome, 
Firefox works properly)

The situation is similar to the question below, but it has not been 
resolved by the proposed solution.
(
https://stackoverflow.com/questions/53186554/django-csrf-token-issue-with-edge-only
)


[Error Page]

You are seeing this message because this HTTPS site requires a “Referer 
header” to be sent by your Web browser, but none was sent. This header is 
required for security reasons, to ensure that your browser is not being 
hijacked by third parties.

If you have configured your browser to disable “Referer” headers, please 
re-enable them, at least for this site, or for HTTPS connections, or for 
“same-origin” requests.

If you are using the <meta name="referrer" content="no-referrer"> tag or 
including the “Referrer-Policy: no-referrer” header, please remove them. 
The CSRF protection requires the “Referer” header to do strict referer 
checking. If you’re concerned about privacy, use alternatives like <a 
rel="noreferrer" …> for links to third-party sites.

Reason given for failure:

    Referer checking failed - no Referer.
   


...



[View.py]


class TslIdDownFormView(TemplateView):
    template_name = 'blog/iddown.html'
    checklist = []

    @csrf_exempt
    def post(self, request, *args, **kwargs):

        checklist = request.POST.getlist('selection')

        return render(request, self.template_name, {'checklist': checklist})​


[url.py]

url_pattern = [
    ...
    path('iddown', TslIdDownFormView.as_view(), name='iddown'),​
    ...
]


[Template.html]

<form action="{% url 'iddown' %}" method="post" id="post_form" 
target="print_popup"
  onsubmit="window.open('about:blank', 'print_popup', 'width=325,height=520');" 
>

  {% csrf_token %}

  <input type="submit" class="iddown btn btn-outline btn-primary pull-right" 
id="selectBtn" value="Download" >​
</form>



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/86299d0a-b517-44a7-84e0-97f493b782bco%40googlegroups.com.

Reply via email to