vim users/models.py
class Singup(models.Model)
email = models.CharField(max_length=50)
password = models.CharField(max_length=50)
Name = models.CharField(max_length=50)
phone_num = models.CharField(max_length=50)
import json
✖ 1 from django.http import JsonResponse
✖ 3 from django.views import View
1 from .models import User
2
3 class SignupView(View):
➤ 4 def post(self, request):
5 ¦ requestpassword = 8
6 ¦
7 ¦ try:
8
9 ¦ ¦ data = json.loads(request.body)
10
11 ¦ ¦ if '@' not in data['email'] or '.' not in data['email']:
12 ¦ ¦ ¦ return JsonResponse({'message':'email validation'},status=400)
13
14 ¦ ¦ if User.objects.filter(email=data['email']).exists():
15 ¦ ¦ ¦ return JsonResponse({'message':'DUPLICATED EMAIL'},status=400)
16 ¦ ¦ if len(data['password']) <= requestpassword :
17 ¦ ¦ ¦ return JsonResponse({'message':'INVALID PASSWORD'},status=400)
18
19 ¦ ¦ User.objects.create(
20 ¦ ¦ ¦ email =data['email'],
21 ¦ ¦ ¦ password = data['password'],
22 ¦ ¦ ¦ name= data['name'],
23 ¦ ¦ ¦ phone_num =data['phone_num']
24 ¦ ¦ )
25 ¦ ¦ return JsonResponse({'message':'SUCCESS'},stats=201)
26
27
28 ¦ except KeyError:
29 ¦ ¦ return JsonResponse({'message':'KEY_ERROR'},status=400)
from django.urls import path,include
2
1 urlpatterns = [
19 ¦ path('users',include('users.urls'))
from django.urls import path
6 from .views import SignupView
5
4
3
2 urlpatterns =[
1 ¦ path('/users', SignupView.as_view()),
8 ¦ # path('/signin', SigninView.as_view())
http -v POST http://127.0.0.1:8080/users/users email=ewfew@co.kr password=232334534 name=hello phone_num=010-2336-6434
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| django |
| dog |
| information_schema |
| mysql |
| owner_dogs |
| performance_schema |
| startbucks |
| sys |
| users |
+--------------------+
9 rows in set (0.00 sec)
mysql> show tables;
+---------------------+
| Tables_in_users |
+---------------------+
| django_content_type |
| django_migrations |
| django_session |
| users_user |
+---------------------+
4 rows in set (0.01 sec)
mysql> select * from users_user
-> ;
+----+-------------+-----------+-------+---------------+
| id | email | password | name | phone_num |
+----+-------------+-----------+-------+---------------+
| 1 | hello | 232334534 | hello | 010-2336-6434 |
| 2 | ewfew@co.kr | 232334534 | hello | 010-2336-6434 |
+----+-------------+-----------+-------+---------------+
2 rows in set (0.00 sec)