code an complete web app similar to Linktree but for Skills, name is Skilltree, do…
- User
code an complete web app similar to Linktree but for Skills, name is Skilltree, do frontend and backend, and sqlite database
- Assistant
code an complete web app similar to Linktree but for Skills, name is Skilltree, do frontend and backend, and sqlite database
Sure! Let's build a web application called Skilltree that allows users to create a personalized page showcasing their skills, similar to how Linktree lets users share multiple links. We'll develop the frontend and backend, and use SQLite for the database.
We'll use the following technologies:
Here's the overall project structure:
skilltree/
├── app.py
├── templates/
│ ├── base.html
│ ├── index.html
│ ├── profile.html
│ └── create_profile.html
├── static/
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── script.js
├── skilltree.db
└── requirements.txt
First, ensure you have Python 3 and pip installed. Create a virtual environment and install Flask.
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install Flask
pip install Flask
# Save dependencies
pip freeze > requirements.txt
We'll create a simple database to store user profiles and their skills.
User Table
id (Integer, Primary Key)username (String)bio (Text)Skills Table
id (Integer, Primary Key)user_id (Integer, Foreign Key to User)skill_name (String)skill_level (String)Create a script to set up the database.
# init_db.py
import sqlite3
conn = sqlite3.connect('skilltree.db')
c = conn.cursor()
# Create User table
c.execute('''
CREATE TABLE IF NOT EXISTS user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
bio TEXT
)
''')
# Create Skills table
c.execute('''
CREATE TABLE IF NOT EXISTS skills (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
skill_name TEXT NOT NULL,
skill_level TEXT,
FOREIGN KEY(user_id) REFERENCES user(id)
)
''')
conn.commit()
conn.close()
print("Database initialized.")
Run the script:
python init_db.py
from flask import Flask, render_template, request, redirect, url_for
import sqlite3
app = Flask(__name__)
# Database connection
def get_db_connection():
conn = sqlite3.connect('skilltree.db')
conn.row_factory = sqlite3.Row
return conn
@app.route('/')
def index():
return render_template('index.html')
@app.route('/<username>')
def profile(username):
conn = get_db_connection()
user = conn.execute('SELECT * FROM user WHERE username = ?', (username,)).fetchone()
if user is None:
return "User not found.", 404
skills = conn.execute('SELECT * FROM skills WHERE user_id = ?', (user['id'],)).fetchall()
conn.close()
return render_template('profile.html', user=user, skills=skills)
@app.route('/create', methods=('GET', 'POST'))
def create_profile():
if request.method == 'POST':
username = request.form['username']
bio = request.form['bio']
skills = request.form.getlist('skill_name')
skill_levels = request.form.getlist('skill_level')
conn = get_db_connection()
try:
conn.execute('INSERT INTO user (username, bio) VALUES (?, ?)', (username, bio))
user_id = conn.execute('SELECT id FROM user WHERE username = ?', (username,)).fetchone()['id']
for skill_name, skill_level in zip(skills, skill_levels):
if skill_name:
conn.execute('INSERT INTO skills (user_id, skill_name, skill_level) VALUES (?, ?, ?)',
(user_id, skill_name, skill_level))
conn.commit()
except sqlite3.IntegrityError:
conn.close()
return "Username already exists.", 400
conn.close()
return redirect(url_for('profile', username=username))
return render_template('create_profile.html')
if __name__ == '__main__':
app.run(debug=True)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Skilltree</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="{{ url_for('index') }}">Skilltree</a>
</nav>
<div class="container">
{% block content %}{% endblock %}
</div>
<!-- Bootstrap JS and dependencies -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
{% extends "base.html" %}
{% block content %}
<div class="jumbotron text-center">
<h1>Welcome to Skilltree</h1>
<p>Create your personal skill profile and share it with the world!</p>
<a href="{{ url_for('create_profile') }}" class="btn btn-primary">Create Your Skilltree</a>
</div>
{% endblock %}
{% extends "base.html" %}
{% block content %}
<h2>Create Your Profile</h2>
<form method="post">
<div class="form-group">
<label for="username">Username (this will be your profile URL):</label>
<input type="text" class="form-control" name="username" required>
</div>
<div class="form-group">
<label for="bio">Short Bio:</label>
<textarea class="form-control" name="bio"></textarea>
</div>
<h4>Skills</h4>
<div id="skills">
<div class="skill-entry">
<div class="form-row">
<div class="col">
<input type="text" class="form-control" name="skill_name" placeholder="Skill Name">
</div>
<div class="col">
<select class="form-control" name="skill_level">
<option value="Beginner">Beginner</option>
<option value="Intermediate">Intermediate</option>
<option value="Expert">Expert</option>
</select>
</div>
</div>
</div>
</div>
<button type="button" id="add-skill" class="btn btn-link">Add Another Skill</button>
<br>
<button type="submit" class="btn btn-success">Create Profile</button>
</form>
<script>
document.getElementById('add-skill').addEventListener('click', function() {
var skillEntry = document.querySelector('.skill-entry');
var newSkillEntry = skillEntry.cloneNode(true);
var inputs = newSkillEntry.querySelectorAll('input');
inputs.forEach(input => input.value = '');
document.getElementById('skills').appendChild(newSkillEntry);
});
</script>
{% endblock %}
{% extends "base.html" %}
{% block content %}
<h2>{{ user['username'] }}'s Skilltree</h2>
<p>{{ user['bio'] }}</p>
<h4>Skills</h4>
<ul class="list-group">
{% for skill in skills %}
<li class="list-group-item">
<strong>{{ skill['skill_name'] }}</strong> - {{ skill['skill_level'] }}
</li>
{% endfor %}
</ul>
{% endblock %}
body {
padding-top: 60px;
}
(You can add more styles as needed.)
Make sure your virtual environment is activated and run:
python app.py
Navigate to http://127.0.0.1:5000/ in your web browser.
Home Page: You'll see a welcome message with an option to create your Skilltree.
Create Profile: Click on "Create Your Skilltree" to go to the profile creation page.
View Profile: After submitting, you'll be redirected to your profile page at http://127.0.0.1:5000/your_username.
Share Profile: You can share your profile URL with others.
Validation: Currently, there's minimal validation. You could add more checks (e.g., ensure username doesn't contain invalid characters).
Authentication: Implement user authentication for profile editing.
Design: Enhance the frontend design with more sophisticated CSS or a frontend framework.
Skills Endorsement: Allow others to endorse skills.
Deployment: To make the app publicly accessible, deploy it on a platform like Heroku or DigitalOcean.
You've now built a basic web application that lets users create and share their own Skilltrees! This foundational app can be expanded with additional features like social integration, profile customization, and more.
Feel free to ask if you have any questions or need further assistance with specific features.
Not yet included in a published release.