2024. 2. 28. 15:35

1. 인증 담당 앱 생성

 

python manage.py startapp xauth

 

2. INSTALLED_APPS 에 xauth 등록

 

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'xauth'

]

 

3. xauth.models.py 에서 AbstractUser를 상속받아 XUser 생성

class XUser(AbstractUser):

  nation = models.CharField(max_length=50)

  USERNAME_FIELD = "email"

 

4. settings.py 에 AUTH_USER_MODEL 등록

AUTH_USER_MODEL = 'xauth.XUser'

5. xauth.admin.py 에서 Admin 에 XUser 등록

admin.site.register(XUser)

 

6. DB 테이블 생성

python manage.py makemigrations

 

python manage.py migrate

 

7. urls.py 에 auth 경로 작성

from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path('admin/', admin.site.urls),

    path('auth/', include('xauth.urls'))

]

 

8. xauth.urls.py 작성

urlpatterns = [

  path('login/', views.loginx, name="loginx"),

  path('logout/', views.logoutx, name="logoutx"),

  path('signup/', views.signupx, name="signupx")

]

 

9. 회원가입 코드 생성

def signupx(request):

  if request.method == "POST":

    username = request.POST['username']

    password = request.POST['password']

    email = request.POST['email']

    nation = request.POST['nation']


    user = User.objects.create_user(username, email, password)

    user.nation= nation

    user.save()

    return redirect('users:login')

10. login 코드 생성

def loginx(request):

  if request.method == "POST":

    post = request.POST

    email = post['email']

    password = post['password']

    user = authenticate(username=email, password=password)

    if user is not None: # login success

      res = login(request, user)

      print(f'res : {res}')

      print('auth success~!')

    else:

      print('auth failed~!')

 

11. logout 코드 생성

def logoutx(request):

  logout(request)

  return redirect('users:login')

12. 버그 수정

XUser 에서 email로 로그인을 하기 위해

 

USERNAME_FIELD 를 설정하면 버그 발생한다

 

AbstractUser 에서 변경해야 함

 

1. email 항목 unique 추가

email = models.EmailField(_("email address"), unique=True, blank=True)

 

2. REQUIRED_FILEDS 에서 email 삭제

#REQUIRED_FIELDS = ["email"]

 

3. createsuperuser 실행할 때 버그 수정

 

AbstractUser 클래스에서

REQUIRED_FIELDS = ["username"]

항목 추가

 

12. 로그인 로그아웃 테스트

2024. 2. 28. 15:00

settings.py 에서

 

LANGUAGE_CODE = 'ko-kr'

 

TIME_ZONE = ''Asia/Seoul"

 

로 변경

2024. 2. 28. 09:20

users_user 테이블의 username이 유일하지 않다

즉 중복 입력했다 이런 뜻이다

 

 

2024. 2. 22. 10:07

 

wheel 을 동작하다가 pkg-config 를 못찾겠어서 나온 버그

 

pkg-config 를 설치해주면 된다

 

pip install pkg-config

 

에러 메세지는 길더라도 차분히 읽어봐야 한다

2024. 2. 20. 13:28

ValueError: unsupported format character ';' (0x3b) at index 216

 

이렇게 나오면 파이썬에서 % 가 escape 문자이기 때문에 수정해야 한다

 

width: 100%; 

 

대신에

 

width: 100%%;

 

이렇게 써야 나온다

2024. 2. 20. 11:15

python manage.py migrate 

 

장고 프로젝트에 미리 정의된 내역대로 데이터베이스 테이블 생성

 

python manage.py createsuperuser

 

슈퍼 유저 계정 생성

2024. 2. 20. 11:10

settings.py 를 참조하면 몇 개 없지만

 

/django/conf/global_settings.py 를 보면

 

690 개가 기본적으로 생성되어 있다

 

이것들과 이름이 같아야 재정의를 

 

올바르게 할 수 있다

2024. 2. 15. 13:17

장고

프로그래밍/Python 2024. 2. 15. 13:17

장고 프로젝트 관리 명령어 모음

 

start app - 앱 생성

runserver - 서버 실행

createsuperuser - 관리자 생성

makemigrations app - app의 모델 변경 사항 체크

migrate - 변경 사항을 DB에 반영

shell - 쉘을 통해 데이터를 확인

collectstatic - static 파일을 한곳에 모음

 

manage.py runserver 0.0.0.0:8080

 

2024. 2. 14. 17:01

1. 가상 환경 생성

 

virtualenv env

 

2. 가상환경 활성화

 

Scripts 폴더 내에 있음

 

cd Scripts

 

activate

 

(env) path

 

3. django 설치

 

pip install django

 

4. django 프로젝트 생성

 

django-admin startproject apple .

 

5. 서버 실행하기 전에 업데이트

 

python manage.py migrate

 

6. 파이썬 서버 실행

 

python manage.py runserver

 

7. 서버 실행 확인

 

127.0.0.1:8000 접속

 

8. app 생성

 

python manage.py startapp sales

 

9. app 등록

 

settings.py 의 INSTALLED_APPS 에 sales 추가

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'sales'

]

 

10. 모델 생성

 

models.py 에 class 생성 후 

 

class Sale(models.Model):

  first_name = models.CharField(max_length=30)

  last_name = models.CharField(max_length=30)

  age = models.IntegerField(default=0)

 

python manage.py makemigrations 입력하여 DB 테이블 생성

 

 

11. DB에 적용

 

python manage.py migrate

2024. 2. 7. 10:59

button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

2024. 2. 7. 10:42

button

 

button.clicked.connect(self.button_clicked)

 

combobox

 

combobox.currentTextChanged.connect(self.combobox_changed)

 

checkbox

 

checkbox.stateChanged.connect(self.checkbox_changed)

 

radio

 

radio.toggled.connect(self.radio1_toggled)

2024. 2. 6. 14:03

지원 버전 OS 가 안 맞아서 그렇다

 

다음을 입력하면 해결된다

 

npm audit fix

2024. 1. 29. 18:11

"http://cors-anywhere.herokuapp.com/{요청 url}"

2024. 1. 10. 16:57

1. 스타일링 코드를 분리해서 소스코드의 가독성 높임

 

2. 이미 정해놓은 스타일을 캐시해서 성능이 좋음

2024. 1. 9. 11:02