It's highly recomended to setup django in a virtual environment
Create a python virtual environment with venv
package
$ python -m venv <environment name>
Source the appropriate environment activation script depending on your shell.
$ source /path/to/environment/bin/activate
Note: activate
without any suffix is for Bash
shell.
Install django in the virtual environment with the following command:
$ pip install -r requirements.txt
$ sudo apt install mysql-server python3-dev libmysqlclient-dev default-libmysqlclient-dev
$ pip install mysqlclient
$ sudo mysql -u root
mysql > source /path/to/script.sql
mysql > CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';
mysql > GRANT ALL PRIVILEGES ON <dbname>.* TO `newuser`@`localhost`;
Do migration only once before starting the server, or after any change to the database model with
python manage.py migrate [port]
Run the server with the following code inside the virtual environment:
python manage.py runserver [port]
Create a user in MySQL with the same name (newuser
) by using createsuperuser
command in django.
python manage.py createsuperuser