This repository has been archived on 2023-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
django-pyvows/sandbox/main/views.py

44 lines
1 KiB
Python
Raw Normal View History

from django.conf import settings
2011-05-10 02:33:07 +00:00
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import NameForm
2011-05-10 02:33:07 +00:00
2011-05-10 02:33:07 +00:00
def home(request):
return HttpResponse('hello world')
2011-08-18 22:39:52 +00:00
2011-08-18 22:39:52 +00:00
def say_hello(request):
SAY_HELLO_WITHOUT_NAME = getattr(settings, "SAY_HELLO_WITHOUT_NAME", False)
if 'name' in request.GET:
name = request.GET['name']
elif SAY_HELLO_WITHOUT_NAME:
2015-07-18 21:25:24 +00:00
name = 'guest'
else:
return HttpResponse("What's your name?")
return HttpResponse("Hello, %s!" % name)
2011-08-22 18:08:00 +00:00
def post_it(request):
return HttpResponse(request.POST['value'])
def post_file(request):
return HttpResponse(request.FILES['the_file'].read().strip())
def post_name(request):
if request.method == 'POST':
form = NameForm(request.POST)
if form.is_valid():
return HttpResponseRedirect(
'/say/?name={}'.format(form.cleaned_data['your_name']))
else:
form = NameForm()
return render(request, 'name.html', {'form': form})