sd4-github / sample-drf

sample drf project
0 stars 0 forks source link

installation #1

Open sd4-github opened 2 hours ago

sd4-github commented 2 hours ago

activate virtual env

soumikd4@soumik-lenovo:~/code/pyEnv$ source venv/bin/activate

(venv) soumikd4@soumik-lenovo:~/code/pyEnv$

sd4-github commented 2 hours ago

no module named pip

python3 -m ensurepip --upgrade

sd4-github commented 1 hour ago

pip install django

pip install djangorestframework

version check

(venv) soumikd4@soumik-lenovo:~/code/pyEnv$ django-admin --version
5.1.2
(venv) soumikd4@soumik-lenovo:~/code/pyEnv$ pip show djangorestframework
Name: djangorestframework
Version: 3.15.2
Summary: Web APIs for Django, made easy.
Home-page: https://www.django-rest-framework.org/
Author: Tom Christie
Author-email: tom@tomchristie.com
License: BSD
Location: /home/soumikd4/code/pyEnv/venv/lib/python3.12/site-packages
Requires: django
Required-by: 

pip freeze

(venv) soumikd4@soumik-lenovo:~/code/pyEnv$ pip freeze
asgiref==3.8.1
Django==5.1.2
djangorestframework==3.15.2
sqlparse==0.5.1

(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ pip freeze > requirements.txt

sd4-github commented 1 hour ago

create project and app

(venv) soumikd4@soumik-lenovo:~/code/django$ django-admin startproject drfProject

(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ django-admin startapp myapp

include rest_framework and myapp in installed apps

image

sd4-github commented 46 minutes ago

after model creation make superuser

image

(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK
(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ 
sd4-github commented 45 minutes ago
(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ python3 manage.py createsuperuser
Username (leave blank to use 'soumikd4'): soumik
Email address: 
Password: 
Password (again): 
Error: Blank passwords aren't allowed.
Password: 
Password (again): 
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

image

sd4-github commented 30 minutes ago

image image

sd4-github commented 24 minutes ago
 File "/home/soumikd4/code/pyEnv/venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 354, in execute
    return super().execute(query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such table: myapp_student

for above error run makemigratons and migrate

(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ python3 manage.py makemigrations
Migrations for 'myapp':
  myapp/migrations/0001_initial.py
    + Create model Student
(venv) soumikd4@soumik-lenovo:~/code/django/drfProject$ python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, myapp, sessions
Running migrations:
  Applying myapp.0001_initial... OK