작정하고 장고 15강 - HTTP 프로토콜 GET, POST : Django로 Pinterest 따라하기!
{% extends 'base.html' %}
{% block content %}
<div style="border-radius: 1rem; margin: 2rem; text-align: center;">
<h1 style="font-family: 'Zen Dots', cursive;">
Hello World LIST!
</h1>
<form action="/account/hello_world" method="POST">
{% csrf_token %}
<div>
<input type="text" name="hello_world_input">
</div>
<div>
<input type="submit" class="btn btn-primary" value="POST">
</div>
</form>
<h1>
{{ text }}
</h1>
</div>
{% endblock %}
from django.shortcuts import render
# Create your views here.
def hello_world(request):
if request.method == "POST":
temp = request.POST.get('hello_world_input')
return render(request, 'accountapp/hello_world.html', context={'text': temp})
else:
return render(request, 'accountapp/hello_world.html', context={'text': 'GET Method!!'})
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from accountapp.models import HelloWorld
def hello_world(request):
if request.method == "POST":
temp = request.POST.get('hello_world_input')
new_hello_world = HelloWorld()
new_hello_world.text = temp
new_hello_world.save()
return render(request, 'accountapp/hello_world.html', context={'hello_world_output': new_hello_world})
else:
return render(request, 'accountapp/hello_world.html', context={'text': 'GET Method!!'})
{% extends 'base.html' %}
{% block content %}
<div style="border-radius: 1rem; margin: 2rem; text-align: center;">
<h1 style="font-family: 'Zen Dots', cursive;">
Hello World LIST!
</h1>
<form action="/account/hello_world" method="POST">
{% csrf_token %}
<div>
<input type="text" name="hello_world_input">
</div>
<div>
<input type="submit" class="btn btn-primary" value="POST">
</div>
</form>
{% if hello_world_output %}
<h1>
{{ hello_world_output.text }}
</h1>
{% endif %}
</div>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div style="border-radius: 1rem; margin: 2rem; text-align: center;">
<h1 style="font-family: 'Zen Dots', cursive;">
Hello World LIST!
</h1>
<form action="/account/hello_world" method="POST">
{% csrf_token %}
<div>
<input type="text" name="hello_world_input">
</div>
<div>
<input type="submit" class="btn btn-primary" value="POST">
</div>
</form>
{% if hello_world_list %}
{% for hello_world in hello_world_list %}
<h4>
{{ hello_world.text }}
</h4>
{% endfor %}
{% endif %}
</div>
{% endblock %}
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from accountapp.models import HelloWorld
def hello_world(request):
if request.method == "POST":
temp = request.POST.get('hello_world_input')
new_hello_world = HelloWorld()
new_hello_world.text = temp
new_hello_world.save()
hello_world_list = HelloWorld.objects.all()
return render(request, 'accountapp/hello_world.html', context={'hello_world_list': hello_world_list})
else:
hello_world_list = HelloWorld.objects.all()
return render(request, 'accountapp/hello_world.html', context={'hello_world_list': hello_world_list})
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse, HttpResponseRedirect
from accountapp.models import HelloWorld
from django.urls import reverse
def hello_world(request):
if request.method == "POST":
temp = request.POST.get('hello_world_input')
new_hello_world = HelloWorld()
new_hello_world.text = temp
new_hello_world.save()
return HttpResponseRedirect(reverse('accountapp:hello_world'))
else:
hello_world_list = HelloWorld.objects.all()
return render(request, 'accountapp/hello_world.html', context={'hello_world_list': hello_world_list})