Django FileNotFoundError at /admin/ [Errno 2] No such file or directory: '/media'

43 Views Asked by At

Website works fine locally but when I try to change or add to the model Trick (which has a FilePathField attribute) in localhost:8000/admin, I get FileNotFoundError [Errno 2] No such file or directory: '/media'.


/login_unecessary_tricks_list/models.py
from django.db import models

class Trick(models.Model):
    video = models.FilePathField(path='/media')
    name = models.CharField(max_length=300)
    author = models.CharField(max_length=75, blank=True)

/project/settings.py
from pathlib import Path
import os

BASE_DIR = Path(__file__).resolve().parent.parent
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

/project/urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
path("", include('login_unnecessary_tricks_list.urls')),
path("", include('op_ed_articles .urls')),
] + static (settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I’m guessing there’s a problem with my media folder implementation, but I don’t know what it is.

0

There are 0 best solutions below