from django.contrib.auth import login
from django.shortcuts import render, redirect
from .forms import SignUpForm
def frontpage(request):
return render(request, 'core/frontpage.html')
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save
login(request, user)
return redirect('frontpage')
else:
form = SignUpForm()
return render(request, 'core/signup.html', {'form': form})
Here is my code, when i signup and hit the submit button, it tells me, that
function’ object has no attribute ‘_meta’ django
the error should be on
login(request, user)
. Thanks for help !
Here is html:
{% extends 'core/base.html' %}
{% block title %}Signup | {% endblock %}
{% block content %}
<div class="p-10 lg:p-20 text-center">
<h1 class="text-3xl lg:text-6xl text-white">Djangochat</h1>
</div>
<form method="post" action="." class="lg:w-1/4 px-4 mx-auto">
{% csrf_token %}
<div class="mb-5">
<label class="text-white">Username</label>
<input type="text" name="username" class="w-full mt-2 px-4 py-2 rounded-xl">
</div>
<div class="mb-5">
<label class="text-white">Password</label>
<input type="password" name="password1" class="w-full mt-2 px-4 py-2 rounded-xl">
</div>
<div class="mb-5">
<label class="text-white">Repeat password</label>
<input type="password" name="password2" class="w-full mt-2 px-4 py-2 rounded-xl">
</div>
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="mb-5 p-4 rounded-xl bg-red-300 text-white">
<p>{{ error|escape }}</p>
</div>
{% endfor %}
{% endfor %}
{% endif %}
<button class="px-5 py-3 rounded-xl text-white bg-teal-800 hover:bg-teal-700">Submit</button>
</form>
{% endblock %}