Everything in my site working after it is up and running. I am using AWS S3 for static files but for some reason I don’t see in my static files the folder for admin. I also tried to add a category and it is successful but when adding products that has photos and videos i get server error 500. here is the code:
views.py
def add_product(request):
submitted = False
if request.method=="POST":
form = ProductForm(request.POST or None, request.FILES or None)
if form.is_valid():
form.save()
return HttpResponseRedirect('/add_product?submitted=True')
else:
form = ProductForm
if 'submitted' in request.GET:
submitted = True
return render(request, 'add_product.html', {'form':form, 'submitted':submitted})
forms.py
class ProductForm(ModelForm):
class Meta:
model = Product
fields = ('name','price','category','digital','image','video_name','video_file', 'video_demo')
labels = {
'name': '',
'price': '',
'category': '',
'digital': 'Digital?',
'image': 'Upload Image',
'video_name': '',
'video_file': 'Upload Video',
'video_demo': 'Upload Video Demo',
}
widgets = {
'name': forms.TextInput(attrs={'class':"form-control", "placeholder":"Product Name"}),
'price': forms.TextInput(attrs={'class':"form-control", "placeholder":"Product Price"}),
'category': forms.Select(attrs={'class':"form-control"}),
'digital': forms.CheckboxInput(attrs={'class':'form-control'}),
'image': forms.FileInput(attrs={'class':'form-control'}),
'video_name': forms.TextInput(attrs={'class':"form-control", "placeholder":"Video Title"}),
'video_file': forms.FileInput(attrs={'class':'form-control'}),
'video_demo': forms.FileInput(attrs={'class':'form-control'}),
}
add_product.html
{% extends 'cart/main.html' %}
{% load static %}
{% block content %}
<center>
<h1>Add New Product</h1>
<center>
<br/><br/>
{% if submitted %}
Your product was added...
{% else %}
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="submit" class="btn btn-secondary">
</form>
{% endif %}
{% endblock content %}
is there something wrong with my code? I tried offline it is working locally but online it is error 500