簡體   English   中英

同一站點 iframe 無法在 Django 中連接

[英]Same-site iframes not able to connect in Django

iframe 顯示無法連接。 我嘗試在視圖上使用默認的@xframe_options_exempt裝飾器,以及 django-csp 的@csp_exempt無濟於事。

給出的控制台錯誤是:

Refused to display 'http://localhost:8000/new_pull/' in a frame because it set 'X-Frame-Options' to 'deny'.

Failed to load resource: the server responded with a status of 404 (Not Found)

看法

@csp_exempt
@login_required
def new_pull(request):
    """Create a new pull request"""

    if request.method != 'POST':
        # No data submitted; create a blank form
        form = PullForm()
    else:
        # POST data submitted; process data
        form = PullForm(data=request.POST)
        if form.is_valid():
            new_pull = form.save(commit=False)
            new_pull.owner = request.user
            new_pull.save()

    # Display a blank or invalid form.
    context = {'form': form}
    return render(request, 'learning_logs/new_pull.html', context)

底座.html

    {% if user.is_authenticated %}
        <br>

        <iframe src="{% url 'learning_logs:new_pull' %}" title="Pull request Iframe"></iframe>
        <iframe src="learning_logs/new_pull.html" title="Pull request Iframe"></iframe>
    {% endif %}

new_pull.html

<div class="pull container text-center border-top mt-5">
    <h5 class="mt-2">Pull request</h5>

    <p>New pull request:</p>
     <form action="{% url 'learning_logs:new_pull' %}" method='post'>
        {% csrf_token %}
        {% bootstrap_form form %}

        {% buttons %}
        <button name="submit" class="btn btn-green pl-2 pr-2">
            <i class="fas fa-plus-circle"></i>
            Create pull
        </button>
        {% endbuttons %}
        <input type="hidden" name="next"
        value="{% url 'learning_logs:bug_tracker' %}" />
    </form>

</div>

嘗試將此添加到Settings.py

X_FRAME_OPTIONS = 'SAMEORIGIN'

默認情況下, the X-Frame-Options設置為Deny

https://docs.djangoproject.com/en/3.0/ref/clickjacking/


這可能不是您的問題,因為有很多原因可能導致此問題,例如 CSP。 沒有我的信息很難確定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM