fuck it im done

static files dont want to show up.
I literally cannot serve static files
This commit is contained in:
Yamozha
2021-02-05 14:27:58 +02:00
parent dac4049cd4
commit 18fb9b25cd
41 changed files with 177 additions and 63 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
from django import forms
from .models import upload_image
class UploadImage(forms.ModelForm):
class Meta:
model = upload_image
fields = [
'image'
]

View File

@ -0,0 +1,23 @@
# Generated by Django 3.1.6 on 2021-02-05 12:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0002_auto_20210205_0037'),
]
operations = [
migrations.AlterField(
model_name='upload_image',
name='image',
field=models.FileField(upload_to='static/images/'),
),
migrations.AlterField(
model_name='upload_video',
name='video',
field=models.FileField(upload_to='static/videos/'),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 3.1.6 on 2021-02-05 12:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0003_auto_20210205_1213'),
]
operations = [
migrations.AlterField(
model_name='upload_image',
name='image',
field=models.FileField(upload_to='images/'),
),
migrations.AlterField(
model_name='upload_video',
name='video',
field=models.FileField(upload_to='videos/'),
),
]

View File

@ -0,0 +1,13 @@
{% extends 'uploadImage.html' %}
{% block replace %}
<div class="jumbotron">
<h1 class="display-4">Welcome to DataFlair<br>Hello {{ user_pr.fname }}</h1>
<p class="lead">its an awesome profile picture</p>
<hr class="my-4">
{% load static %}
<img src="{% static user_pr.image.url %}" class="image_responsive" height="100px" width="100px">
<p>
{{ user_pr.display_picture.url }}<BR>
You have learned some awesome technologies like {{ user_pr.technologies }}</p>
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>404</h1>
</body>
</html>

View File

@ -1,10 +1,25 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<h1>test 1</h1>
</body>
<html>
<head>
<title>Make Profile</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<center>
<div class="jumbotron">
<h1 class="display-4">DataFlair Django File Uploading</h1>
{% block replace %}
<p class="lead">To make a user profile and upload the files fill this form</p>
<hr class="my-4">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" class="btn btn-primary btn-lg" name="register">
</div>
</center>
{% endblock %}
</body>
</html>

View File

@ -1,40 +1,67 @@
from django.shortcuts import render, redirect
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
return upload_image(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
# 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
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
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)