본문 바로가기

Python_WEB/Try_Django

[Django]Submit Raw HTML Form

반응형

CodingEntrepreneurs Django 강의 정리

HTML 방식의 Form>

<form> </form>

 

csrf_token>

1. CSRF보호에 사용

 

2. CSRF토큰이 누출되어 취약성을 초래할 수 있으므로 외부 URL을 대상으로 하는 POST양식에 대해서는 수행해서는

   안된다.

 

3. 일반 뷰 또는 콘트리브 애플리케이션을 사용하는 경우 이 모든 것이 사용되기 때문에 이미 적용

 

csrk>

1. 악성 사이트를 방문하는 로그인한 사용자의 자격 증명을 사용하여 웹 사이트에서 일부 작업을 수행하려는 링크,

   양식 버튼 또는 일부 JavaScript가 악성 웹 사이트에 포함되어 있을 때 발생

 

2.  공격 사이트가 다른 사용자의 자격 증명으로 사용자의 브라우저를 속여 사이트에 로그인하는 '로그인 CSRF'라는

    관련 공격 유형

 

base.html>

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
        integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

    <title>{% block head_title %} Replace this value {% endblock %} CFE</title>
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-6 mx-auto">
                <!-- <h1>{{ title }}</h1> -->
                {% block content %}
                <!-- Replace this value -->
                {% endblock %}
            </div>
        </div>
    </div>


    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
        integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
        crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
        integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
        crossorigin="anonymous"></script>
</body>

</html>

 

form.html>

{% extends "base.html" %}

{% block content %}

{% if title %}
<h1>{{ title }}</h1>
{% endif %}

<form method="POST" action="."> {% csrf_token %}
    <input type="text" name="full_name">
    <input type="email" name="email">
    <textarea name="content"></textarea>
    <button type="submit">Send</button>
</form>

{% endblock %}

 

views>

from django.http import HttpResponse
from django.shortcuts import render
from django.template.loader import get_template

# Model View Template (MVT)
# Dont Repeat Yourself = DRY
def home_page(request):
    my_title = "Hello there ..."
    context = {"title": "my_title"}
    if request.user.is_authenticated:
        context = {"title": my_title, "my_list": [1, 2, 3, 4, 5]}
    # template_name = "title.txt"
    # template_obj = get_template(template_name)
    # rendered_string = template_obj.render(context)
    # print(rendered_string)
    # doc = "<h1>{title}</h1>".format(title=my_title)
    # django_render_doc = "<h1>{{ title }}</h1>".format(title=my_title)
    # return render(request, "hello_world.html", {"title": rendered_string})
    return render(request, "home.html", context)


def about_page(request):
    return render(request, "about.html", {"title": "About Us"})


def contact_page(request):
    print(request.POST)
    return render(request, "form.html", {"title": "Contact Us"})


def example_page(request):
    context = {"title": "Example"}
    template_name = "hello_world.html"
    template_obj = get_template(template_name)
    rendered_item = template_obj.render(context)
    return HttpResponse(rendered_item)
반응형

'Python_WEB > Try_Django' 카테고리의 다른 글

[Django]Saving Data from a Django Form  (0) 2020.06.17
[Django]A Django Form  (0) 2020.06.17
[Django]In App Templates  (0) 2020.06.17
[Django]Include URLs  (0) 2020.06.17
[Django]Routing the Views  (0) 2020.06.16