Answer the question
In order to leave comments, you need to log in
Can't make a user profile?
Hello, please help! I can't make a user profile.
Error: Migrations
folder (0001_initial.py) :
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize$
('image', models.ImageField(default='default.jpg', upload_to='profile_$
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASC$
],
),
]
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
def __str__(self):
return f'{self.user.username} Profile'
from django.shortcuts import render, redirect
from django.contrib import messages
from .forms import UserOurRegistration
from django.contrib.auth.decorators import login_required
def register(request):
if request.method == "POST":
form = UserOurRegistration(request.POST);
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
return redirect('home')
else:
form = UserOurRegistration()
return render(request, 'users/registration.html', {'form': form})
@login_required
def profile(request):
return render(request, 'users/profile.html')
% extends 'web/main.html' %}
{% load crispy_forms_tags %}
{% block title_page %}
<title>Авторизация на сайте</title>
{% endblock title_page %}
{% block content %}
<div class="container" style="margin-top: 5%;">
<div class="form-section">
<h2>Авторизация</h2>
<form method="POST">
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-ouline-warning">Войти</button>
</form>
<hr>
Нету профиля? <a href="{% url 'reg' %}">Зарегистрироваться</a>
</div>
</div>
{% endblock content %}
Answer the question
In order to leave comments, you need to log in
A user profile must also be created. Ideally, at the User post_save signal, to cover all possible places of creation at once.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question