-
Notifications
You must be signed in to change notification settings - Fork 0
/
new django project
46 lines (27 loc) · 1.85 KB
/
new django project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Virtual environment setup
python -m venv project-name
project-name\Scripts\activate.bat
İzole çalışma ortamı kurulduktan sonra aktive edip Django kurulumunu gerçekleştiriyoruz.
pip install Django
django-admin startproject blogproject diyerek yeni bir django projesi şablonu oluşturuyoruz.
cd blogproject
Herhangi bir işlem yapmadan önce Custom User modeli tanımlayacağız.
Substituting a custom User model¶
Some kinds of projects may have authentication requirements for which Django’s built-in User model is not always appropriate. For instance, on some sites it makes more sense to use an email address as your identification token instead of a username.
Django allows you to override the default user model by providing a value for the AUTH_USER_MODEL setting that references a custom model:
AUTH_USER_MODEL = "myapp.MyUser"
This dotted pair describes the label of the Django app (which must be in your INSTALLED_APPS), and the name of the Django model that you wish to use as your user model.
Using a custom user model when starting a project¶
If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the default User model is sufficient for you. This model behaves identically to the default user model, but you’ll be able to customize it in the future if the need arises:
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
Don’t forget to point AUTH_USER_MODEL to it. Do this before creating any migrations or running manage.py migrate for the first time.
Also, register the model in the app’s admin.py:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, UserAdmin)
Ardından python manage.py makemigrations
python manage.py migrate
python manage.py runserver