Django
0
Вклад в тег
from django.db import models
class Article(models.Model):
file_obj = models.FileField(upload_to='media/')
from django.shortcuts import render
from django.contrib.auth import authenticate
from django.http import HttpResponseRedirect
from .forms import ArticleForm
def Upload_file(request):
if request.method == 'POST':
form = ArticleForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = ArticleForm()
return render(request, 'file_upload.html', {'form': form})
from django.forms import ModelForm
from .models import Article
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['file_obj']