Skip to content

Commit

Permalink
Merge pull request #2 from hexlet-components/get-form
Browse files Browse the repository at this point in the history
Get form
  • Loading branch information
sgmdlt authored Aug 14, 2024
2 parents fed93f7 + 5fe1984 commit 84868e3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
25 changes: 20 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
from flask import Flask, render_template
from flask import Flask, render_template, request

app = Flask(__name__)

users = [
{'id': 1, 'name': 'mike'},
{'id': 2, 'name': 'mishel'},
{'id': 3, 'name': 'adel'},
{'id': 4, 'name': 'keks'},
{'id': 5, 'name': 'kamila'}
]


@app.route('/')
def hello_world():
return 'Welcome to Flask!'


@app.get('/users')
def users_get():
return 'GET /users'
@app.route('/users/')
def get_users():
term = request.args.get('term', '')
print(users)
filtered_users = [user for user in users if term in user['name']]
return render_template(
'users/index.html',
users=filtered_users,
search=term,
)


@app.post('/users')
def users():
def post_users():
return 'Users', 302


Expand Down
18 changes: 0 additions & 18 deletions templates/courses/index.html

This file was deleted.

23 changes: 23 additions & 0 deletions templates/users/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "users/layout.html" %}

{% block title %}Пользователи{% endblock %}

{% block content %}
<form action="/users" method="get">
<input type="search" name="term" value="{{ search }}" />
<input type="submit" value="Search" />
</form>

<table>
{% for user in users %}
<tr>
<td>
{{ user.id }}
</td>
<td>
{{ user.name }}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% block sidebar %}
<ul>
<li><a href="/">Главная</a></li>
<li><a href="/courses/">Курсы</a></li>
<li><a href="/users/">Пользователи</a></li>
</ul>
{% endblock %}
</div>
Expand Down

0 comments on commit 84868e3

Please sign in to comment.