navbar current decorator

This commit is contained in:
2024-08-05 09:09:51 -07:00
parent 82baefb3d2
commit 2ba3fe0a7e
8 changed files with 54 additions and 59 deletions

View File

@ -48,7 +48,7 @@ def explore():
next_url = url_for('explore', page=posts.next_num) if posts.has_next else None
prev_url = url_for('explore', page=posts.prev_num) if posts.has_prev else None
return render_template('index.html', title='Explore', posts=posts.items, next_url=next_url, prev_url=prev_url)
return render_template('explore.html', title='Explore', posts=posts.items, next_url=next_url, prev_url=prev_url)
@app.route('/login', methods=['GET', 'POST'])
def login():

View File

@ -11,12 +11,12 @@
<body>
<header>
<nav>
<a href="{{ url_for('index') }}">home</a>
<a href="{{ url_for('explore') }}">explore</a>
<a {% block indexcurrent %}{% endblock %} href="{{ url_for('index') }}">home</a>
<a {% block explorecurrent %}{% endblock %} href="{{ url_for('explore') }}">explore</a>
{% if current_user.is_anonymous %}
<a href="{{ url_for('login') }}">login</a>
<a {% block logincurrent %}{% endblock %} href="{{ url_for('login') }}">login</a>
{% else %}
<a href="{{ url_for('user', username=current_user.username) }}">profile</a>
<a {% block profilecurrent %}{% endblock %} href="{{ url_for('user', username=current_user.username) }}">profile</a>
<a href="{{ url_for('logout') }}">logout</a>
{% endif %}

View File

@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block explorecurrent %}class="current"{% endblock %}
{% block content %}
<h1>Hello, {{ current_user.username }}!</h1>
{% if form %}
<form action="" method="post">
{{ form.hidden_tag() }}
<p>
{{ form.post.label }}
{{ form.post(cols=32, rows=4) }}
{% for error in form.post.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>{{ form.submit() }}</p>
</form>
{% endif %}
{% for post in posts %}
{% include '_post.html' %}
{% endfor %}
{% if prev_url %}<a href="{{ prev_url }}">Newer Posts</a>{% endif %}
{% if next_url %}<a href="{{ next_url }}">Older Posts</a>{% endif %}
{% endblock %}

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block indexcurrent %}class="current"{% endblock %}
{% block content %}
<h1>Hello, {{ current_user.username }}!</h1>
{% if form %}

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block logincurrent %}class="current"{% endblock %}
{% block content %}
<h1>Sign In</h1>
<form action="" method="post" novalidate>

View File

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block profilecurrent %}class="current"{% endblock %}
{% block content %}
<table>
<tr valign="top">