This video is a part of my web development using flask and python playlist –
Source Code here –
Web development in python is one of the most requested tutorial series, I get over email. As the popularity of python increases, people become more and more interested in topics like how to send email using flask, how to connect to a database in python flask, how to make rest API in flask etc. In this video I have shown how to make a full complete tech blog from start to finish using flask python.
Click here to subscribe –
Best Hindi Videos For Learning Programming:
►Learn Python In One Video –
►Learn JavaScript in One Video –
►Learn PHP In One Video –
►Machine Learning Using Python –
►Creating & Hosting A Website (Tech Blog) Using Python –
►Advanced Python Tutorials –
►Object Oriented Programming In Python –
►Python Data Science and Big Data Tutorials –
Follow Me On Social Media
►Website (created using Flask) –
►Facebook –
►Instagram (Guaranteed Replies :)) –
►Personal Facebook A/c –
Twitter –
Nguồn: https://benjaminjcohen.com/
Xem thêm bài viết khác: https://benjaminjcohen.com/cong-nghe/
I am getting an error UnboundLocalError: local variable 'username' referenced before assignment.
if anyone know how to solve plz reply
Harry ji is tutorial ka code kaha hai ?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.adm{
width:35%;
margin: 13px;
margin-left: 32.5%;
margin-right: 32.5%;;
display: inline;
box-sizing: border-box;
text-align: center;
}
.body{
width:60%;
margin: auto;
padding: 10%;
margin-top: 103px;
}
.sec{
width:50%;
margin: auto;
}
</style>
</head>
<body>
<div class="body">
<div class="sec">
<form action="/Admin.html" method="POST">
<input type="text" class = 'adm' placeholder="ID" name="uid">
<br>
<input class = 'adm' type="password" name="upass" placeholder="Password">
<br>
<input type="submit" name = Submit class = 'adm'>
</form>
</div>
</div>
</body>
</html>
# Following is the website for my personal use made using python concepts like jinja
# templating , flask and mysql. I hope everyone will enjoy it
from flask import Flask, render_template, request, session
from flask_sqlalchemy import SQLAlchemy
import datetime as d
import json
from flask_mail import Mail
#——————————————————————–
app = Flask(__name__)
app.secret_key = 'super secret key'
with open('config.json', 'r') as c:
par = json.load(c)["parametres"]
# following is the piece of code which will send us email
app.config.update(
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = '465',
MAIL_USE_SSL = True,
MAIL_USERNAME = par['gmail-user'],
MAIL_PASSWORD= par['gmail-pass']
)
mail = Mail(app)
app.config['SQLALCHEMY_DATABASE_URI'] = par["Local_Server_Uri"]
db = SQLAlchemy(app)
#following is the class which will handle my project details
class Project(db.Model):
sno = db.Column(db.Integer , primary_key = True)
project_name = db.Column(db.String(100), unique=False, nullable=False)
project_desc = db.Column(db.String(500), unique=False, nullable=False)
project_video = db.Column(db.String(10), unique=False, nullable=False)
project_link = db.Column(db.String(60) , unique = False , nullable = False)
class Contacts(db.Model):
sno = db.Column(db.Integer, primary_key=True)
Name = db.Column(db.String(100), unique=False, nullable=False )
Email = db.Column(db.String(100), unique=False, nullable=False)
Message = db.Column(db.String(100), unique=False, nullable=False)
class Posts(db.Model):
sno = db.Column(db.Integer, primary_key=True)
Title = db.Column(db.String(100), unique=False, nullable=False)
Description = db.Column(db.String(100), unique=False, nullable=False)
Image = db.Column(db.String(100), unique=False, nullable=False)
Category = db.Column(db.String(30), unique=False, nullable=False)
Content = db.Column(db.String(500), unique=False, nullable=False)
Slug = db.Column(db.String(60), unique=False, nullable=False)
Date = db.Column(db.String(12), nullable=True)
@app.route('/')
def home():
current_year = int(d.datetime.now().year)
return render_template('index.html', par=par)
@app.route('/index.html')
def index():
current_year = int(d.datetime.now().year)
return render_template('index.html', year = current_year, par=par)
@app.route('/AboutME.html')
def About():
current_year = int(d.datetime.now().year)
return render_template('AboutMe.html' , year = current_year, par=par)
#——————————————————————————–
@app.route('/ContactForum.html' , methods=["GET","POST"] )
def cont():
if(request.method == 'POST'):
""" Add entry to the database """
name = request.form.get('Name')
email = request.form.get('Email')
message = request.form.get('Message')
# in the contacts table , i have the following attributes
# Name varchar(100)
# Email varchar(100)
# Message varchar(1000)
entry = Contacts(Name = name , Email = email , Message = message)
db.session.add(entry)
db.session.commit()
mail.send_message('New message from ' + name,
sender=email,
recipients=[par['gmail-user']],
body=message + "n" +email
)
current_year = int(d.datetime.now().year)
return render_template('ContactForum.html', year = current_year, par=par)
#——————————————————————————–
@app.route('/education.html')
def education():
current_year = int(d.datetime.now().year)
return render_template('education.html',year = current_year, par=par)
@app.route('/Post.html')
def Blog():
current_year = int(d.datetime.now().year)
Poste = Posts.query.filter_by().all()
return render_template('Post.html' , year = current_year , par=par , posts = Poste)
@app.route('/Projects.html')
def Project():
current_year = int(d.datetime.now().year)
return render_template('Projects.html' , year = current_year, par=par)
@app.route('/Cont.html/<string:post_slug>' , methods = ['GET'])
def open(post_slug):
post = Posts.query.filter_by(Slug = post_slug).first()
return render_template('Cont.html' , par = par , post = post)
@app.route('/Admin.html' , methods = ['GET' , 'POST'])
def admin():
if 'user' in session and session['user'] == par["Admin_User_Name"]:
# following will tell us weather the user was already logged in
return render_template('dashboard.html')
if request.method == 'POST':
username = request.form.get('uid')
password = request.form.get('upass')
if (username == par["Admin_User_Name"] and password == par["Admin_User_Pass"]):
#set the session variable
session['User'] = username # we can write any name in session
return render_template('dashboard.html')
return render_template('Admin.html' , par = par)
@app.errorhandler(404)
def page_not_found(e):
# note that we set the 404 status explicitly
return "render_template('404.html')", 404
app.run(debug=True)
Bhai source code nhi h please bhai source code dee doo
Best video bro
Bro you will get more subscribers
I pray to God. You r excellent bto
*Harry bhai Code provide karo plz……. *
Where is code of this video?
8:39 cigrate ki dibbi,….hahahaha
mena bhi sg125998@gmail.com se pel kr shre kr diya ha
behtreen course
Your Teaching skill is too good…We Learn a lot of things…You deserve 1M Subscribers & we hope will get this at the end of this year
you are doing best love from pakistan
Sir apna yeah newer posts ka button banana sekhaya nhi
If anyone having key error ‘user’ , then add this session [‘user’]=0 just before your session [‘user’] = username
jinja2.exceptions.TemplateNotFound: dashboard.hmtl
500 to 270k that's an incredible achievement bro. Keep up the good work
Harry bhai … your explanation makes very easy to understand difficult concepts … this full tutorial helps me to build such an amazing websites …thanks bhai .
KeyError ko kaise fix karen?
Bhai,
KeyError = 'user'
how to fix this problem?
Bhai flask me database me se image kese print kare ??? :((((((
Thora or clear koro bhay