My Blog

My WordPress Blog

My Blog

My WordPress Blog

Custom CRM System

Step 1: Set Up the Environment

  1. Install Flask: You can install Flask and other dependencies using pip. Create a virtual environment first for better management.
mkdir custom_crm cd custom_crm python -m venv venv source venv/bin/activate # On Windows use venv\Scripts\activate pip install Flask Flask-SQLAlchemy
  1. Project Structure: Your project structure should look something like this:
custom_crm/ ├── app.py ├── models.py ├── templates/ │ ├── index.html │ ├── add_customer.html └── venv/

Step 2: Create the Models

In models.py, define the database models. For simplicity, we’ll create a Customer model.

pythonCopy code# models.py
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
phone = db.Column(db.String(15))
notes = db.Column(db.Text)
def __repr__(self):
    return f'<Customer {self.name}>'

Step 3: Create the Flask Application

In app.py, set up the Flask app and routes.

# app.py
from flask import Flask, render_template, request, redirect, url_for
from models import db, Customer

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

with app.app_context():
db.create_all()
@app.route('/') def index():
customers = Customer.query.all()
return render_template('index.html', customers=customers)
@app.route('/add', methods=['GET', 'POST']) def add_customer():
if request.method == 'POST':
    name = request.form['name']
    email = request.form['email']
    phone = request.form['phone']
    notes = request.form['notes']
    new_customer = Customer(name=name, email=email, phone=phone, notes=notes)
    db.session.add(new_customer)
    db.session.commit()
    return redirect(url_for('index'))
return render_template('add_customer.html')
if __name__ == '__main__':
app.run(debug=True)

Step 4: Create the HTML Templates

Create a simple HTML template for the customer list and the form to add new customers.

templates/index.html:

<!DOCTYPE html>
<html>
<head>
&lt;title>CRM System&lt;/title>
</head> <body>
&lt;h1>Customer List&lt;/h1>
&lt;a href="/add">Add Customer&lt;/a>
&lt;ul>
    {% for customer in customers %}
        &lt;li>{{ customer.name }} - {{ customer.email }}&lt;/li>
    {% endfor %}
&lt;/ul>
</body> </html>

templates/add_customer.html:

<!DOCTYPE html>
<html>
<head>
&lt;title>Add Customer&lt;/title>
</head> <body>
&lt;h1>Add New Customer&lt;/h1>
&lt;form method="POST">
    Name: &lt;input type="text" name="name" required>&lt;br>
    Email: &lt;input type="email" name="email" required>&lt;br>
    Phone: &lt;input type="text" name="phone">&lt;br>
    Notes: &lt;textarea name="notes">&lt;/textarea>&lt;br>
    &lt;input type="submit" value="Add Customer">
&lt;/form>
</body> </html>

Step 5: Run the Application

  1. Initialize the Database: If you haven’t created the database yet, run the application once to initialize it.
  2. Run the Flask App:bashCopy codepython app.py
  3. Access the CRM: Open your browser and go to http://127.0.0.1:5000/ to see your CRM in action!

Custom CRM System

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top