Browse Source

first

master
Artur 5 years ago
parent
commit
03664012b5
4 changed files with 29 additions and 4 deletions
  1. +1
    -0
      jauns_projekts/jauns_projekts/urls.py
  2. +4
    -2
      jauns_projekts/templates/form.html
  3. +2
    -0
      jauns_projekts/templates/hello.html
  4. +22
    -2
      jauns_projekts/uzdevumi/views.py

+ 1
- 0
jauns_projekts/jauns_projekts/urls.py View File

@ -22,5 +22,6 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('show-hello', uzdevumi.views.show_hello),
path('show-html', uzdevumi.views.show_html),
path('university', uzdevumi.views.form),
]

+ 4
- 2
jauns_projekts/templates/form.html View File

@ -7,8 +7,10 @@
<body>
<form action="" method="post">
{% csrf_token %}
First name: <input type="text" name="first_name">
Last name: <input type="text" name="last_name">
Full name: <input type="text" name="fullname"><br>
Mathematics: <input type="text" name="mathematics"><br>
Latvian language: <input type="text" name="latvian_lng"><br>
Foreign language: <input type="text" name="foreign_lng"><br>
<input type="submit">
</form>
</body>


+ 2
- 0
jauns_projekts/templates/hello.html View File

@ -6,5 +6,7 @@
</head>
<body>
<h1>Current datetime: {{ dateadntime }}</h1>
<h1>Current datetime: {{ dateadntime }}</h1>
</body>
</html>

+ 22
- 2
jauns_projekts/uzdevumi/views.py View File

@ -2,6 +2,7 @@ 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!')
@ -21,11 +22,11 @@ def show_html(request):
context=context,
)
def show_name(request):
def show_name(request):
# ja submit, tad metode POST
if request.method == 'POST':
# input nosaukums
# input nosaukums
first_name = request.POST['first_name']
last_name = request.POST['last_name']
@ -36,3 +37,22 @@ def show_name(request):
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',
)

Loading…
Cancel
Save