class Input(View):
def get(self, request):
form = inpForm()
return render(request, 'index.html', {'form': form})
def post(self, request):
form = inpForm(request.POST)
if form.is_valid():
text = form.cleaned_data['post']
form = inpForm()
return render(request, 'index.html', {'form': form, 'text': text})
translateFri, 17 Feb 2023 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("First message");
Console.ReadLine();
}
}
}
class IndexView(FormView):
template_name = 'index.html'
form_class = ArticleForm
success_url = '/search/'
def form_valid(self, form):
self.request.session['name'] = form.cleaned_data['name']
self.request.session['author'] = form.cleaned_data['author']
return super().form_valid(form)
def __str__(self):
return self.language
<style>
.content {
font-weight: bold;
font-style: italic;
}
</style>
<!DOCTYPE html>
<html>
<head>
<title>
{% block title_block %}
{{ title_text }}
{% endblock %}
</title>
</head>
<body>
<div class="container" id="main">
{% block content %}
{% endblock %}
</div>
</body>
</html>
from django import forms
class NewPostForm(forms.Form):
title = forms.CharField()
description = forms.CharField(widget=forms.Textarea)
class inputText(forms.Form):
input_text = forms.CharField(label='Input Text', strip=True, widget=forms.Textarea(attrs={'placeholder':'Enter text here...'}))
def authors_is_alive_name(author):
list_authors = []
for i in author:
list_authors.append(i[0] + ' ' + i[1])
return list_authors
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
from django.shortcuts import render
# Create your views here.
def index(request):
title_text = "Привет, это django проект созданный с использование нейросети"
return render(request, 'index.html', {'title_text': title_text})
SELECT title, first_name, last_name, language_id, summary FROM catalog_book
INNER JOIN catalog_author ON (catalog_book.author_id = catalog_author.id)
SELECT title, first_name, last_name FROM catalog_book LEFT JOIN authors ON catalog_book.author_id = authors.id;
{% extends "base_generic.html" %}
{% block title %}{{title_text}}{% endblock %}
{% block content %}
{% endblock %}
class Task:
def __init__(self, text, maxlength=10, words=False):
self.words = words
self.maxlength = maxlength
self.text = text
class TaskWithWrap(Task):
def __init__(self, text, maxlength=10):
super(TaskWithWrap, self).__init__(text, maxlength, words=False)
class TaskWithWords(Task):
def __init__(self, text, maxlength=10):
super(TaskWithWords, self).__init__(text, maxlength, words=True)
class TextField(Field):
def __init__(self, max_length=200, min_length=None, *args, **kwargs):
self.max_length, self.min_length = max_length, min_length
super().__init__(*args, **kwargs)
def index(request):
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()
num_instances_available = BookInstance.objects.filter(status__exact='a').count()
num_authors = Author.objects.count()
# Количество авторов которые ещё живы
num_authors_is_alive = Author.objects.filter(date_of_death__exact=None).count
authors_is_alive_name = list(Author.objects.values_list('first_name', 'last_name').filter(date_of_death__exact=None))
return render(
request, 'index.html',
context=
{'num_books': num_books, 'num_instances': num_instances, 'num_instances_available': num_instances_available,
'num_authors':
class inpForm(forms.Form):
name = forms.CharField(label='Введите имя:')
email = forms.CharField(label='Введите e-mail:')
translateFri, 17 Feb 2023 public class BookInstance
{
public int BookInstanceID { get; set; }
public int BookID { get; set; }
public Guid Id { get; set; }
public String Imprint { get; set; }
public DateTime DueBack { get; set; }
public String Status { get; set; }
public virtual Book Book { get; set; }
}
SELECT title FROM catalog_book;
class ContactForm(forms.Form):
name = forms.CharField(max_length=100, required=True)
message = forms.CharField(widget=forms.Textarea, required=True)
def clean(self):
cleaned_data = super(ContactForm, self).clean()
name = cleaned_data.get("name")
message = cleaned_data.get("message")
if name == "django":
raise forms.ValidationError("Django is a framework, not a person")
authors_is_alive_name = []
for author in Author.objects.all():
if not author.date_of_death:
authors_is_alive_name.append([author.first_name, author.last_name])
class inpForm(forms.Form):
city = forms.CharField(label='Введите город:')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'main.css' %}">
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
# Create your views here.
from django.shortcuts import render
class PostForm(forms.Form):
class Meta:
model = Post
fields = ('title', 'text')
class CreatePostView(CreateView):
model = Post
form_class = PostForm
template_name = 'create_post.html'
success_url = reverse_lazy('index')
class book(models.Model):
name = models.CharField(max_length=400)
author = models.CharField(max_length=400)
short_description = models.TextField()
genre = models.CharField(max_length=400)
language = models.ManyToManyField(language)
def __str__(self):
return self.name
SELECT cb.title, ca.first_name||' '||ca.last_name as author, cb.summary, cl.name
FROM catalog_book cb
inner join catalog_author ca on cb.author_id=ca.id
left join catalog_language cl on cl.id=cb.language_id
WHERE date_of_death is null;
SELECT title,first_name,last_name,summary,language_id
FROM catalog_book b
JOIN catalog_author a ON b.author_id=a.id
JOIN catalog_bookinstance bi ON b.id=bi.book_id
WHERE bi.status='o' AND a.date_of_death IS NULL;
class inpForm(forms.Form):
name = forms.CharField(label="Имя")
email = forms.EmailField(label="Имейл")
text = forms.CharField(widget=forms.Textarea)
SELECT cat.title, cat_aut.first_name, cat.summary, cat_lan.name as language
FROM catalog_book as cat
LEFT JOIN catalog_author as cat_aut ON cat_aut.id=cat.author_id
LEFT JOIN catalog_language as cat_lan ON cat_lan.id=cat.language_id
LEFT JOIN catalog_bookinstance as cat_ins ON cat_ins.book_id=cat.id
WHERE cat_aut.date_of_death IS NULL
AND cat_ins.status='o';
class MyBook(models.Model):
name = models.CharField(max_length=100)
author = models.CharField(max_length=100)
short_description = models.TextField()
genre = models.CharField(max_length=100)
language = models.ManyToManyField(Language)
def __str__(self):
return self.name_text
class Language(models.Model):
language = models.CharField(max_length=100)
def __str__(self):
return self.language_text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{{ title_text }}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
class ManageTextForm:
texto = ""
resultado = ""
def __init__(self, texto_recibido):
self.texto = texto_recibido
self.resultado = self.texto.split()
class IndexView(TemplateView):
template_name = 'index.html'
def get(self, request):
form = ManageTextForm()
return render(request, self.template_name, {'form':form})
def post(self, request):
form = ManageTextForm(request.POST['text'])
return render(request, self.template_name, {'form':form})
translateFri, 17 Feb 2023 namespace ContosoUniversity.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
}
}
EXAMPLE:
class ExampleClassView(View):
template_name = "index.html"
def get(self, request):
return render(request, self.template_name, {'form': ExampleForm(),
'another_form': AnotherForm()},)
SELECT cb.title, ca.first_name, ca.last_name, cb.summary, cl.name
FROM catalog_book cb
INNER JOIN catalog_author ca ON cb.author_id=ca.id
INNER JOIN catalog_language cl ON cb.language_id=cl.id
INNER JOIN catalog_bookinstance cbi ON cb.id=cbi.book_id
WHERE ca.date_of_death IS NULL AND cbi.status='o';
.body {
font-style: italic;
}
.head{
font-weight: bolder;
}
def get_alive_authors_list(authors_is_alive_name):
return ["{} {}".format(author[0], author[1]) for author in authors_is_alive_name]
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
email = forms.EmailField(required=False)
message = forms.CharField(widget=forms.Textarea)
from django.views.generic import TemplateView
from django.shortcuts import render
from django.shortcuts import redirect
from django.utils import timezone
from .models import Post
from .forms import PostForm
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
class PostListView(TemplateView):
def get(self, request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request, 'blog/post_list.html', {'posts': posts})
class PersonForm(forms.Form):
name = forms.CharField(max_length=32)
age = forms.IntegerField(min_value=0, max_value=120)
<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<title>{% block title %}general title{% endblock %}</title>
</head>
<body>
{% include "sidebar.html" %}
{% block content %}
general content
{% endblock %}
</body>
</html>
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,"index.html")
def analyze(request):
djtext = request.POST.get('text','default')
removepunc = request.POST.get('removepunc','off')
fullcaps = request.POST.get('fullcaps','off')
newlineremover = request.POST.get('newlineremover','off')
extraspaceremover = request.POST.get('extraspaceremover','off')
charcounter = request.POST.get('charcounter','off')
#check which checkbox is on
if removepunc == 'on':
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed = ""
for char in djtext:
if char not in punctuations:
analyzed = analyzed + char
params = {'purpose':'