Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

handling files in django

from django.shortcuts import render
from .forms import GeeksForm
from .models import GeeksModel
 
# Create your views here.
def home_view(request):
    context = {}
    if request.method == "POST":
        form = GeeksForm(request.POST, request.FILES)
        if form.is_valid():
            name = form.cleaned_data.get("name")
            img = form.cleaned_data.get("geeks_field")
            obj = GeeksModel.objects.create(
                                 title = name,
                                 img = img
                                 )
            obj.save()
            print(obj)
    else:
        form = GeeksForm()
    context['form']= form
    return render(request, "home.html", context)
Comment

PREVIOUS NEXT
Code Example
Python :: python static typing 
Python :: convert set to list python time complexity method 1 
Python :: print anything in python 
Python :: python zeep- SOAP protocol -WSDL/XSD?XML 
Python :: change tag name using beautifulsoup python 
Python :: python rest api interview questions 
Python :: Generating variations on image data 
Python :: clear list in python 
Python :: jntuk r20 1-2 python lab manual 
Python :: how to write def 
Python :: pandas concatenation (concat) using list comprehension 
Python :: emi calculator python code 
Python :: Python create time slot within duration 
Python :: eastcoders: django-meta-class 
Python :: jax.numpy 
Python :: django queryset or operator 
Python :: pyqt5.direct connection 
Python :: heads or tails python 
Python :: How did you determine the chromosome numbers and how does that relate to heredity? 
Python :: how to make ui dialog pop in front pyqt 
Python :: i want to get only first record of each user in pandas 
Python :: set shortcut for Qaction pyqt5 
Python :: dictionnaire 
Python :: sqlalchemy create engine SQLite Relative 
Python :: flask pass an array of dicts 
Python :: fancy index python 
Python :: rich content field django ckeditor not showing bullets 
Python :: NxN Array 
Python :: function for permutation sampling and test statistic from a specified operation 
Python :: compresser fichier pyhton 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =