Это мои models.py
class Donors(models.Model):
category = models.CharField(max_length=4, choices=CATEGORY)
cat_id = models.AutoField(primary_key=True)
p_no = models.PositiveIntegerField()
p_name = models.CharField(max_length=20)
desc = models.TextField()
img = models.FileField(upload_to = 'pic_folder/%Y/%m/%d')
donor_name = models.CharField(max_length=50)
phno = models.CharField(max_length=10)
price = models.PositiveIntegerField()
h_no = models.PositiveIntegerField()
city = models.CharField(max_length=3, choices=CITY)
state = models.CharField(max_length=20)
pincode = models.CharField(max_length=6)
country = models.CharField(max_length=20, default="India",
editable="False")
def __str__(self):
return self.category
это мои views.py
def item(request):
if request.method == "POST":
form = DonorsForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('donor:item',)
else:
form = DonorsForm()
return render(request, 'donor/item.html', {'form': form})
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
это мой главный проект urls.py
from django.urls import path, include
from django.contrib import admin
from django.conf import settings
from django.contrib.staticfiles.urls import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('', include('blog.urls')),
path('donor/', include('donor.urls')),
]
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
и это мой HTML-шаблон
{% extends 'donor/donor_info.html' %}
{% load bootstrap4 %}
{% load crispy_forms_tags %}
{% block content %}
<h1>Item Details</h1>
<div class="container">
<form method="POST" class="post-form" action="{% url 'donor:item' %}">{%
csrf_token %}
{{ form|crispy }}
<br/>
<div class="col-md-6">
<button type="submit" class="save btn btn-default">Save</button>
</div>
</form>
</div>
{% endblock %}
где я иду не так? после всего этого я тоже не могу хранить свои изображения.
Как визуализировать изображения в HTML-шаблонах?