Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit def751c

Browse files
committed
added ability to create form posts
1 parent 0e44c16 commit def751c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sqlite3
2-
from flask import Flask, render_template
2+
from flask import Flask, render_template, request, url_for, flash, redirect
33
from werkzeug.exceptions import abort
44

55
# DATABASE FUNCTIONS
@@ -18,6 +18,7 @@ def get_post(post_id):
1818
return post
1919

2020
app = Flask(__name__)
21+
app.config['SECRET_KEY'] = 'your secret key'
2122

2223
# VIEW FUNCTIONS
2324
@app.route('/')
@@ -30,4 +31,8 @@ def index():
3031
@app.route('/<int:post_id>')
3132
def post(post_id):
3233
post = get_post(post_id)
33-
return render_template('post.html', post=post)
34+
return render_template('post.html', post=post)
35+
36+
@app.route('/create', methods=('GET', 'POST'))
37+
def create():
38+
return render_template('create.html')

templates/create.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends 'base.html' %} {% block content %}
2+
3+
<h2>{% block title %} Create a New Post {% endblock %}</h2>
4+
<form action="" method="post">
5+
<div class="form-group">
6+
<label for="title">Title</label>
7+
<input type="text" name="tittle" placeholder="Post title" class="form-control" value="{{ request.form['title'] }}"></input>
8+
</div>
9+
10+
<div class="form-group">
11+
<label for="content">Content</label>
12+
<textarea name="content" placeholder="Post content" class="form-control">{{ request.form['content'] }}</textarea>
13+
</div>
14+
<div class="form-group">
15+
<button type="submit" class="btn btn-primary">Submit</button>
16+
</div>
17+
</form>
18+
{% endblock %}

0 commit comments

Comments
 (0)