User Stream
Aug 12 2016- POSTED BY projecth
[user_stream.html] {% extends “stream.html” %} {% block content %} <div class=”row”> <div class=”grid-25″> <h1>{{ user.username }}</h1> </div> <div class=”grid-50″> <div […]
Read More[user_stream.html] {% extends “stream.html” %} {% block content %} <div class=”row”> <div class=”grid-25″> <h1>{{ user.username }}</h1> </div> <div class=”grid-50″> <div […]
Read More[app.py] … @app.route(‘/stream’) @app.route(‘/stream/’) def stream(username=None): template = ‘stream.html’ if username and username != current_user.username: user = models.User.select().where(models.User.username**username).get() stream = […]
Read More[app.py] from flask_login import (LoginManager, login_user, logout_user, login_required, current_user) … @app.before_request def before_request(): “””Connect to the database before each request.””” […]
Read MoreLinks for Authenticated Users [layout.html] … <div class=”grid-33″> <!– Say Hi –> <h1>Hello {% if current_user.is_authenticated %}{{ current_user.username }}{% endif […]
Read More[models.py] import datetime from flask_bcrypt import generate_password_hash from flask_login import UserMixin from peewee import * DATABASE = SqliteDatabase(‘social.db’) class User(UserMixin, […]
Read MoreLogin Algorithm Create login form – from data if available. After submitting valid data, get requested user from the database. […]
Read MoreRegistration View [app.py] from flask import Flask, g, render_template, redirect, url_for, flash from flask_login import LoginManager import forms import models […]
Read MoreFlask-WTF Forms are not only about display (i.e. HTML forms), forms are about validation. We will be building a registration […]
Read MorePart of setting up the database is handling connecting and disconnecting from our database responsibly. To do that, we use […]
Read Morebcrypt A famous super strong library that does Cryptographic Hashing using the Blowfish Cypher which is a salt (i.e. random […]
Read MoreBuilding The Model First we’ll build the model that will handle the credential data of the registering users. [models.py] import […]
Read More[diary.py] #!/user/bin/env python3 import datetime import sys import os from collections import OrderedDict from peewee import * db = SqliteDatabase(‘diary.db’) […]
Read More[diary.py] #!/user/bin/env python3 from collections import OrderedDict import datetime from peewee import * db = SqliteDatabase(‘diary.db’) class Entry(Model): content = […]
Read MoreORMs Once upon a time, if you needed to interact with a database, you had to write SQL. But now […]
Read MorePython Code Flash is a Flask function. It uses the user’s session to display messages. Sessions in Flask are cryptographically […]
Read More[app.py]: from flask import (Flask, render_template, request, redirect, make_response, url_for) import json from options import DEFAULTS app = Flask(__name__) @app.route(‘/’) […]
Read MoreCookies are for storing data between requests that our users submit through the form. Cookies are a great way for […]
Read MoreSimple Cookie Set & Get [simpleform.html]: <form action=”{{ url_for(‘setcookie’) }}” method=”POST”> <h3>Enter userID</h3> <input name=”fullname” type=”text” /> <input type=”submit” value=”Submit” […]
Read More