SHARE
TWEET

Untitled

a guest Jun 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. **views.py**
  2. from django.shortcuts import render
  3. from django.views.generic import TemplateView, CreateView
  4. from django.http import HttpResponse
  5. from .models import Post
  6.  
  7. class HomePageView(CreateView):
  8.     model = Post
  9.     template_name = 'home.html'
  10.     fields = ['body', ]
  11.  
  12. class AboutPageView(TemplateView):
  13.     template_name = 'about.html'
  14.  
  15.  
  16.  
  17. **models.py**
  18. from django.core import validators
  19. from django.db import models
  20. from django.urls import reverse
  21.  
  22. from .validators import isalphavalidator
  23.  
  24.  
  25. class Post(models.Model):
  26.     regex = r'^[A-z][w ]{2,31}$'
  27.     body = models.CharField(validators=[isalphavalidator],
  28.                             max_length=30, null=False, blank=False, unique=True)
  29.  
  30.     def str(self):
  31.         return self.body
  32.  
  33.     def get_absolute_url(self):
  34.         return reverse('about')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top