My footer doesn’t use any view I need to get information to save it I used parcel rendering package to render but I don’t get any information to save it even if it’s a small tip I can find it
views code:
def footernews(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
form.save()
return render(request, 'includes/footer.html', {'myformmews': form})
else:
raise ValidationError('sorry infomations dont save...')
else:
form = ContactForm()
return render(request,'includes/footer.html',{'myformmews':form})
models code:
from django.db import models
class MassageNewsFoot(models.Model):
email=models.EmailField(max_length=32)
date=models.DateField(auto_now_add=True)
def __str__(self):
return f'email: {self.email}---date: {self.date}'
forms code:
from django import forms
from home_app.models import MassageNewsFoot
from django.core.exceptions import ValidationError
class ContactForm(forms.ModelForm):
class Meta:
model = MassageNewsFoot
fields = '__all__'
#style form footer in widget
widgets ={
'email': forms.TextInput(attrs={'class':'form-control bordered bottom-only'
,'placeholder':'enter your email'}),
}
urls code:
from django.urls import path
from . import views
app_name = 'home_app'
urlpatterns = [
path("", views.Homepage.as_view(), name='home'),
path("footer", views.footernews, name='footerrenderded'),
]
template code:
<form action="" method="post">
{% csrf_token %}
<div class="subscribe-form">
<div class="head">
news this site
</div>
<div class="input-wrap">
{{ myformmews.email }}
<button class="btn btn-primary" type="submit">
<span class="outer-wrap">
<span data-text="share">
share
</span>
</span>
</button>
</div>
</form>
And finally I gave it to template home:
{% extends 'base.html' %}
{% load static %}
{% load render_partial %}
{% block content %}
html code ...
{% render_partial 'home_app:footerrenderded' %}
{% endblock %}
The message I receive:
If you know how to render a template that is not rendered by any view and receive the data, I would be grateful if you could help me.