Application Web permettant l'application des tests d'intrusion.
To create a django app we need at first install it's framework
We can install it globally on the machine which is not recommended because for some project we may need different django versions.
So we have to create a virtual environement on which we gonna install our django.
-
navigate to your project folder
-
open your command prompt (windows)
-
run this command
python -m venv <nameOfvirtualEnvironement>
- Then we type this next command to activate the virtual environement
<nameOfvirtualEnvironement>\Scripts\activate
- We type this command to install django on our virtual environement
pip install Django
- To create a Django project we type this command:
django-admin startproject <projectName> .
Notice: new folder created with some bunch of python files a manage.py file is created
- To run the Django server we type this command
python manage.py runserver
If you don't want to repeat the command each time, you can open the project folder with PyCharm IDE, and run manage.py, then go to edit configurations, and put runserver as a parameter, then you can run the server by only pressing the run button.
- Until now we have only created a django project, bascially a django project can contain multiple apps, so to create an App we run this command in terminal
django-admin startapp <appName>
- Install mysqlclient package (mysql connector), it will be used by django to connect to mysql server
pip install mysqlclient- Add API to INSTALLED_APPS in settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'API'
]- Change Database configuration in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<DB_NAME>',
'USER': '<DB_USER>',
'PASSWORD': '<DB_PASSWORD>',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}- run this command to migrate modifications and installations to database
python manage.py migrate
- To see what is in our database as an administrator, we can create a user admin with this command
python manage.py createsuperuser
- create a Model in model.py then run these two commands
python manage.py makemigrations
python manage.py migrate
- add these two lines of code to admins.py where model is the name of the Model
from .models import Model
admin.site.register(Model)-
Make sure you have installed python and Django framework (globally or on a virtual environement)
-
Check the version of your python by running on terminal or command prompt this command
python
- Install MySQL by downloading it from it's official site.
during the installation a useradmin and password are required, make sure you keep them in mind and not forget them.
- Configure MySQL with Django by changing DATABASES Constant in setting.py to this
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': '<username>',
'NAME': '<database name>',
'PASSWORD': '<your paswword that you have entered>',
'PORT': '5432'
}
}