03-6 회원가입 구현하고 있는데 에러가 뜹니다.
장고 에서 런서버를 할 경우 뜨는 에러 메세지
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "F:\big7\django\common\urls.py", line 4, in <module>
from . import views
File "F:\big7\django\common\views.py", line 3, in <module>
from common.forms import UserForm
File "F:\big7\django\common\forms.py", line 6, in <module>
class UserForm(UserCreationForm):
File "F:\big7\django\jumptodjango\lib\site-packages\django\forms\models.py", line 268, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (Username) specified for User
아래는 관련 화일입니다.
세번 넘게 확인했는데 어디가 잘못되었는지 찾지 못했습니다. 도움을 주시면 감사하겠습니다.
# **views.py**
from django.shortcuts import render,redirect
from django.contrib.auth import authenticate,login
from common.forms import UserForm
# Create your views here.
def signup(request):
'''
Sign Up
'''
if request.method=="POST":
form=UserForm(request.POST)
if form.is_valid():
form.save()
username=form.cleaned_data.get('username')
raw_password=form.cleaned_data.get('passowrd1')
user=authenticate(username=username, password=raw_password)
login(request,user)
return redirect('index')
else:
form=UserForm()
return render(request,'common/signup.html', {'form':form})
**common/forms.py**
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class UserForm(UserCreationForm):
email=forms.EmailField(label='email')
class Meta:
model=User
fields=("Username","email")
common/urls.py
from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
app_name='common'
urlpatterns=[
path('login/',auth_views.LoginView.as_view(template_name='common/login.html'),name='login'),
path('logout/',auth_views.LogoutView.as_view(),name='logout'),
path('signup/',views.signup, name='signup'),
]
common/signup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% extends "base.html" %}
{% block content %}
<div class="container my-3">
<div class="row my-3">
<div class="col-4">
<h4>SignUp</h4>
</div>
<div class="col-8 text-right">
<span> OR <a href="{% url 'common:login' %}"> Log In </a></span>
</div>
</div>
<form method="post" clas="post-form">
{% csrf_token %}
{% include "form_errors.html" %}
<div class="form-group">
<label for="username">User Name</label>
<input type="text" class="form-control" name="username" id="username"
value="{{form.usrname.value|default_if_none:''}}">
</div>
<div class="form-group">
<label for="password1">Password</label>
<input type="password" class="form-control" name="password1" id="password1"
value="{{form.password1.value|default_if_none:''}}">
</div>
<div class="form-group">
<label for="password2">confirm Password</label>
<input type="password" class="form-control" name="password2" id="password2"
value="{{form.password2.value|default_if_none:''}}">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email"
value="{{form.email.value|default_if_none:''}}">
</div>
<button type="submit" calss="btn btn-primary">Create</button>
</form>
</div>
</body>
</html>
common/login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="row">
<div class="col-4">
<h4>LogIn</h4>
</div>
<div calss="col-8 text-right">
<span>
OR <a href="{% url 'common:signup' %}"> create an account</a>
</span>
</div>
</div>
<form method="post" class="post-form" action="{% url 'pybo:login' %}">
</form>
</body>
</html>
최원호 님 2079
M 2021년 3월 8일 7:15 오후