Answer the question
In order to leave comments, you need to log in
How to send context to django models?
The form:
class CreatePostForm(ModelForm):
class Meta:
model = Post
fields = ['title', 'text', 'spoiler']
widgets = {
'title': TextInput(attrs={
'class': 'new-form-input',
'placeholder': 'Header...'
}),
'text': Textarea(attrs={
'class': 'comment-form',
'placeholder': 'Text...'
}
),
}
class Post(models.Model):
spoiler = models.ImageField(upload_to='user_images/')
likes = models.IntegerField()
title = models.CharField(max_length=200)
text = models.TextField()
owner = models.ForeignKey(User, on_delete=models.CASCADE)
views = models.IntegerField()
create_date = models.DateTimeField(auto_now_add=True)
def get_absolute_url(self):
return f'news/{self.id}'
def __str__(self):
return self.title
<center>
<div class="logo">
<span class="re">Authorization</span> account<br>
</div>
{% if error %}
<br>
<div class="error">
<span class="re" style="font-size: 20px;">Error</span><br><br>
<span>{{ error }}</span>
</div>
{% endif %}
<form method="post">
{% csrf_token %}
{{ form.username }}
{{ form.password }}
<p style="color: white;">You don't have account? - <a href="{% url 'registration' %}">registration</a></p>
<button type="submit">Authorization </button>
<br>
</form>
</center>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question