Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

createview django

# Required imports
from django.urls import reverse_lazy

class YourView(CreateView):
	model 			= Model
    fields 			= ['your_fields']
    template_name 	= 'your_template'
    success_url		= reverse_lazy('home')
    
    def form_valid(self, form):
        form.instance.user = self.request.user
        super(YourView, self).form_valid(form)
        return redirect('home')
Comment

django view

from django.http import HttpResponse #last line below allows MyView.get 
# to return an HttpResponse object 
from django.views import View #View is to become the parent class of MyView

class MyView(View):
	''' View is the parent class that provides method as_view() to MyView '''
    def get(self, request, *args, **kwargs):
        return HttpResponse('Hello, World!')
Comment

Django Create View

class AuthorCreateView(CreateView):
    form_class = AuthorForm
    template_name = 'author_new.html'
    success_url = 'success'
Comment

django create view class

###### views.py #####
from .forms import  CreateArticleForm
from django.views.generic import CreateView
class ArticleCreateView(CreateView):
    form_class = CreateArticleForm
    template_name = 'articles/create_article.html'
    
###### urls.py  ######
from .views import ArticleCreateView
urlpatterns =[ path('articles/create/', ArticleCreateView.as_view()),]
Comment

create views django

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def hola(request):
    return HttpResponse("Hola Mundo, Esto es Django")
Comment

PREVIOUS NEXT
Code Example
Python :: how to loop through pages of pdf using python 
Python :: python remove .0 
Python :: flat numpy array 
Python :: #finding the similarity among two sets 
Python :: python requests post form data 
Python :: pandas filter on two columns 
Python :: django choicefield empty label 
Python :: how to find the cosine in python 
Python :: atan2 of number python 
Python :: python excel file 
Python :: concatenation array 
Python :: how to find unique values in numpy array 
Python :: web driver module in python 
Python :: size of set python 
Python :: username python 
Python :: python write into file at position 
Python :: python zip folder and subfolders 
Python :: power in python 
Python :: check if all elements in list are equal 
Python :: python not in 
Python :: python staticmethod property 
Python :: how to make a python program on odd and even 
Python :: python change dictionary key 
Python :: download pdf python 
Python :: making ckeditor django responsive 
Python :: matrix diagonal sum python 
Python :: matplotlib histogram frequency labels 
Python :: create a database in python 
Python :: list vs tuple python 
Python :: pandas knn imputer 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =