I am new in Django. I am working on a project where user will able to add a file of type .doc, .img, .pdf, .csv.
Uploaded files are expected to be stored in media folder but they don't appear there.
Here is my code:
models.py
class Resources(models.Model):
resource_name = models.CharField(max_length=255)
rec_file = models.FileField(upload_to = "resources/", max_length=10000, null=True, default=None)
created_at = models.DateField(auto_now=True)
views.py
def add_resources(request):
title="Add Resources"
requesturl = request.get_full_path
title = 'Create Clinic'
if request.method == "POST":
resource_name = request.POST.get('resource_name')
resource_file = request.POST.get('resource_file')
resource_instances = Resources.objects.create(
resource_name = resource_name,
rec_file = resource_file
)
resource_instances.save()
return render(request, 'add_resources.html',{'title':title, 'requesturl':requesturl})
settings.py
MEDIA_ROOT = BASE_DIR/"media"
MEDIA_URL = "/media/"
urls.py
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns+=static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
When I upload the file it just saves the file name and nothing is saved in the media folder.