The Local Dev Setup Cheat Sheet I Wish I Had When I Started ๐โก
๐๏ธ Project WITHOUT React/Vite (Python backend + plain HTML/CSS/JS frontend) Backend : source .venv/bin/activate python app.py Frontend (no build tool needed โ just serve the static files): python3 -m http.server 5500 or right-click index.html โ "Open with Live Server" if you're in VS Code. โ๏ธ Project WITH React/Vite (Python backend) Backend : source .venv/bin/activate python app.py Frontend :โฆ
Creating a development environment for a Python backend and HTML/CSS/JS frontend can seem daunting, especially for newcomers. However, with a simple cheat sheet, you can set up your project quickly and efficiently.
For a backend-only project, start by activating your virtual environment with `source .venv/bin/activate` and then run `python app.py` to start your backend server. For the frontend, simply serve the static files using `python3 -m http.server 5500` or in VS Code, right-click on `index.html` and select "Open with Live Server".
If you're working on a project that uses React and Vite, the setup process is a bit different. Again, start by activating your virtual environment and running `python app.py` for your backend server. For the frontend, you'll need to use `npm run dev` to start the development server.
When managing your virtual environment, it's important to know how to delete and create fresh ones. To delete an existing environment, deactivate it with `deactivate` and then remove the directory with `rm -rf .venv`. To create a new one, simply run `python3 -m venv .venv` and then activate it with `source .venv/bin/activate`. Remember to install your required packages with `pip install -r requirements.txt`.
Before starting your server, check if your virtual environment exists by listing the files in your directory with `ls -a`. Look for the `.venv` folder in the list. To confirm that your environment is active, run `which python`. The output should point to the Python executable inside your virtual environment.
It's crucial to verify that your virtual environment is active before running your server. Sometimes, the prompt may misleadingly display a `.venv` label, but this doesn't guarantee that your environment is active. Always double-check with the methods described above.
Finally, only repeat the first-time setup steps under certain circumstances. If you delete your virtual environment, start on a new machine, or update your `requirements.txt` with new packages, you'll need to recreate your environment. Otherwise, simply activate your existing environment and run your server.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.