Django upload file url configuration error

error configuring url while re-learning django configuration upload file

from django.conf.urls import url
from . import views
from django.conf import settings
from .upload import upload_image

urlpatterns = [
-sharp 
    url(r"^$", views.index, name="index"),
    url(r"^uploads/(?P<path>.*)$", "django.views.static.serve", {"document_root": settings.MEDIA_ROOT, }),
    url(r"^admin/upload/(?P<dir_name>[^/]+)$", upload_image, name="upload_image"),
]

the prompt message requires the format of list / tuple. No format error seems to be found, so ask for help. The django version is 1.11

.
  File "C:\Users\kuangcuisheng\Desktop\cytxt\bbnews\bbnews\***\urls.py", line 13, in <module>
    url(r"^uploads/(?P<path>.*)$", "django.views.static.serve", {"document_root": settings.MEDIA_ROOT, }),
 
    raise TypeError("view must be a callable or a list/tuple in the case of include().")
TypeError: view must be a callable or a list/tuple in the case of include().
Feb.26,2021

I took care of it myself, because serve () changed the way I wrote it in 1.11.

from django.conf import settings
from django.views.static import serve

-sharp ... the rest of your URLconf goes here ...

if settings.DEBUG:
    urlpatterns += [
        url(r'^media/(?P<path>.*)$', serve, {
            'document_root': settings.MEDIA_ROOT,
        }),
    ]

from https://docs.djangoproject.co.

Menu