0% found this document useful (0 votes)
19 views2 pages

ERP Flask SQLite Practice Notes

Uploaded by

ArifAslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

ERP Flask SQLite Practice Notes

Uploaded by

ArifAslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

ERP with Flask & SQLite – Practice Notes for Repetition

-------------------------------------------------------

1. Create Project Folder


- Name: ARIF_ERP

2. Open Folder in VS Code


- File → Open Folder → Select ARIF_ERP

3. Create Python Files


- [Link] → Main Flask application
- [Link] → SQLAlchemy models

4. Create Templates Folder


- Folder: templates
- File inside: [Link] → HTML for customer form and list

5. Set Up Virtual Environment


> python -m venv venv
> venv\Scripts\activate

6. Install Required Packages


> pip install flask flask_sqlalchemy

7. Enable Autocomplete (IntelliSense)


- Open Extensions (Ctrl + Shift + X)
- Install:
- Python (by Microsoft)
- Pylance

8. Select Python Interpreter


- Ctrl + Shift + P → "Python: Select Interpreter"
- Choose: .\venv\Scripts\[Link]

9. Write Code in [Link]


-----------------------------------
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class Customer([Link]):
id = [Link]([Link], primary_key=True)
name = [Link]([Link](100))
email = [Link]([Link](100))
-----------------------------------

10. Write Code in [Link]


-----------------------------------
from flask import Flask, render_template, request, redirect
from arifmodels import db, Customer

app = Flask(__name__)
[Link]['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///[Link]'
[Link]['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)

with app.app_context():
db.create_all()
@[Link]('/', methods=['GET', 'POST'])
def add_customer():
if [Link] == 'POST':
name = [Link]['name']
email = [Link]['email']
new_customer = Customer(name=name, email=email)
[Link](new_customer)
[Link]()
return redirect('/')

customers = [Link]()
return render_template('[Link]', customers=customers)

if __name__ == '__main__':
[Link](debug=True)
-----------------------------------

11. Write HTML in templates/[Link]


-----------------------------------
<!DOCTYPE html>
<html>
<head>
<title>Customer Form</title>
</head>
<body>
<h2>Add Customer</h2>
<form method="POST">
Name: <input type="text" name="name"><br><br>
Email: <input type="text" name="email"><br><br>
<input type="submit" value="Add Customer">
</form>
<h3>Customer List</h3>
<ul>
{% for customer in customers %}
<li>{{ [Link] }} - {{ [Link] }}</li>
{% endfor %}
</ul>
</body>
</html>
-----------------------------------

12. Run the App


> python [Link]
Open: [Link]

13. View SQLite Database


- Install SQLite Viewer extension in VS Code
- Open [Link] from Explorer tab

You might also like