/django-rest-crud

Django CRUD example

Primary LanguagePython

Django REST CRUD Application

Create a Django application

  1. Create a virtual environment.
python3 -m venv env_name
  1. Activate Virtual environment.
# macos
source env_name/bin/activate 
  1. Install dependencies.
pip install django djangorestframework
  1. Create a django project.
python django-admin startproject *project_name*
  1. Create a django app.
cd *project_name*
python manage.py startapp *app_ma,e*
  1. Run the django project.
python manage.py runserver 0.0.0.0:8000 # you can use any port here, i'm mr 8000 <3

Bonjour! your first django up and running...

upload project to github

Smash me to show-up
  1. cd into the base directory of your project.
cd /where/you/want/to/go
  1. Initialize git repository.
git init
  1. Add files that are going to be included in first commit.
# git add single file
git add *file_name*

# git add everything inside current directory
git add .
  1. Create a commit
git commit -m 'initial commit'
  1. Create github repository.

  2. Add remote link to your project.

git remote add origin https://github.com/your/project.git
  1. Create main branch
git branch -M main
  1. push to github.
git push -u origin main
  1. Add .gitignore file.
# macos
touch .gitignore
  1. Add directories or files which are not going to pushed to github.
dir/
__pycache__/ # ignone pycache directory
*.pyc # ignore all py cache files
*.sqlite3 # ignore database file

Configure Debugger for vs code

cclick here to expand
  1. Create a launch.json file
mkdir .vscode
cd .vscode
touch launch.json
  1. Add following content to the launch.josn.
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Django",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/backend/manage.py", // location for manage.py file
            "args": [
                "runserver",
                "5000" // specify the port
            ],
            "django": true
        }
    ]
}
  1. Add python interpreter location to vs code.
  • press command + P.
  • Type > on the text section appear very top of the IDE.
  • Click on Python: Select Interpreter.
  • Enter python executable location there.(vnev python location)
ex: ~/Desktop/projects/my_app/venv/bin/python