This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
Yamozha 18fb9b25cd fuck it im done
static files dont want to show up.
I literally cannot serve static files
2021-02-05 14:27:58 +02:00

68 lines
2.2 KiB
Python

# from django.shortcuts import render, redirect
# import os
# from .models import upload_video,upload_image
#
# def imageUpload(request):
# if request.method == "GET":
# return render(request, "uploadImage.html")
# elif request.method == "POST":
# image = request.POST["image"]
# # add the id of the user, after you add in users
# savingImage = open(f"../images/{image}","w")
# for i in image:
# savingImage.write(i)
# savingImage.close()
# return redirect(f"/images/{image}")
# else:
# return
#
# def videoUpload(request):
# if request.method == "GET":
# return render(request, "uploadVideo.html")
# elif request.method == "POST":
# video = request.POST["video"]
# # add the id of the user, after you add in users
# return upload_video(video)
# else:
# return
#
# # these functions do the same thing, but i cant merge them in one, because i cant add parameters(because of request)
#
# def upload_content(request):
# if request.method == "GET":
# return render(request, "index.html")
# elif request.method == "POST":
# choice = request.POST["choices"]
# if choice == "image":
# return redirect("/upload_image/")
# elif choice == "video":
# return redirect("/upload_video/")
# else:
# return
# else:
# return
# # in conclusion - im genious, good job boyan lmao
from django.shortcuts import render
from .forms import UploadImage
from .models import upload_image
IMAGE_FILE_TYPES = ['png', 'jpg', 'jpeg']
def finallyUploadImage(request):
form = UploadImage()
if request.method == 'POST':
form = UploadImage(request.POST, request.FILES)
if form.is_valid():
user_pr = form.save(commit=False)
user_pr.image = request.FILES['image']
file_type = user_pr.image.url.split('.')[-1]
file_type = file_type.lower()
if file_type not in IMAGE_FILE_TYPES:
return render(request, 'error.html')
user_pr.save()
return render(request, 'details.html', {'user_pr': user_pr})
context = {"form": form,}
return render(request, 'uploadImage.html', context)