Patstāvīgais darbs 11.11.2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.7 KiB

from django.shortcuts import render
from django.http import HttpResponse
from datetime import datetime
# Create your views here.
def show_hello(request):
return HttpResponse('Hello!')
def show_html(request):
context = {
'mainigais': 77,
'kautkascits': 'čau no konteksta!',
'a': sum([1, 5]),
'dateadntime': datetime.today()
}
return render(
request,
template_name='hello.html',
context=context,
)
def show_name(request):
# ja submit, tad metode POST
if request.method == 'POST':
# input nosaukums
first_name = request.POST['first_name']
last_name = request.POST['last_name']
return HttpResponse(f'{first_name} {last_name}')
# šis parādās pie metodes GET (kad ievadam /show-name)
return render(
request,
template_name='form.html',
)
def form(request):
# ja submit, tad metode POST
if request.method == 'POST':
# input nosaukums
fullname = request.POST['fullname']
mathematics = int(request.POST['mathematics'])
latvian_lng = int(request.POST['latvian_lng'])
foreign_lng = int(request.POST['foreign_lng'])
if mathematics < 40 or latvian_lng < 40 or foreign_lng < 40:
return HttpResponse(f'{fullname} can not apply to university')
else:
return HttpResponse(f'Hello, {fullname}! You can apply to our university. Your grades: Mathematics: {mathematics}, Latviesu vld: {latvian_lng}, Svesvaloda: {foreign_lng}')
# šis parādās pie metodes GET (kad ievadam /show-name)
return render(
request,
template_name='form.html',
)