Sup, need to use a function in a different class without losing the model, while still being able to change the function(not important, I can rewrite func into more flexible func). Can't solve this issue at least 10 hours. Google didnt help =( I know code is a little dirty, I will clean that :D
Don't worry
I have same header with form and another form in all pages.
Need form from class head in class stockpage. And everyone template and future classes as well.
Views
class head(View):
template_name = "dental/mainpage.html"
model = signup
def get(self,request):
if request.method == 'GET':
form = UserSign
return render(request, "dental/mainpage.html", {"form": form})
def FormSign(self,request):
if request.method == 'POST':
form = UserSign
if form.is_valid():
body = {
'Name': form.cleaned_data['Name'],
'email': form.cleaned_data['email'],
'Number': form.cleaned_data['Number'],
}
info_user = "\n".join(body.values())
send_mail(
'Sign',
info_user,
'[email protected]',
['[email protected]'],
fail_silently=False)
return render(request, "dental/mainpage.html", {"form": form}) #self.template_name
return render(request, "dental/mainpage.html", {"form": form})
class stockpage(ListView):
template_name = "dental/stocks.html"
model = stock
context_object_name = "stocks"
HTML
signuphtml
{% load static %}
{%block css_files %}
<link rel="stylesheet" href="{% static "signup.css" %}">
{% endblock %}
{% block content %}
<section id="forms">
<form action="" method="post">
{% csrf_token %}
<div id="txt" class="form-control {% if form.errors %}invalid{% endif %}">
{{ form.label_tag }}
{{ form }}
{{ form.errors }}
</div>
<div id="buttsig">
<button id="b4" type="submit">записаться</button>
</div>
</form>
</section>
{% endblock content %}
mainpage.html
{% extends 'main.html' %}
{% load static %}
{%block css_files %}
<link rel="stylesheet" href="{% static "header.css" %}">
<link rel="stylesheet" href="{% static "mainpage.css" %}">
<link rel="stylesheet" href="{% static "signup.css" %}">
<link rel="stylesheet" href="{% static 'assets/css/bootstrap.css' %}">
{% endblock %}
{% block title %}{% endblock %}
{% block content %}
{% include "dental/includes/header.html" %}
<div ="d1">
<ul>
<li>blabla</li>
<li>blabla</li>
<li>blabla</li>
<li>blabla</li>
</ul>
</div>
{% include "dental/includes/signup.html" %}
{% include "dental/includes/tail.html" %}
{% endblock content %}
stocks html
{% extends 'main.html' %}
{% load static %}
{%block css_files %}
<link rel="stylesheet" href="{% static "header.css" %}">
<link rel="stylesheet" href="{% static "mainpage.css" %}">
<link rel="stylesheet" href="{% static "signup.css" %}">
<link rel="stylesheet" href="{% static 'assets/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static "stocks.css" %}">
{% endblock %}
{% block title %}{% endblock %}
{% block content %}
{% include "dental/includes/header.html" %}
<section id="contentstock">
{% for stock in stocks %}
<li>
<h4>{{ stock.title }}</h4>
<img src="{{ stock.image.url }}" alt="{{ stock.image }}"/>
<h4>{{ stock.content|linebreaks}}</p>
</li>
{% endfor %}
</section>
{% include "dental/includes/signup.html" %}
{% include "dental/includes/tail.html" %}
{% endblock content %}
{% include %}d fragment for the form on each page (or inherit it as a block from a super-template).