Я только что разместил свой проект django на heroku, и он получает внутреннюю ошибку сервера

2022-07-11T09:25:52.180154+00:00 app[web.1]: from django.urls import path, include,re_path,url

здесь я получил ошибку

мой url-файл

from django.contrib import admin

from django.urls import path, include, re_path, url

from django.conf import settings

from django.conf.urls.static import static

from django.views.static import serve

urlpatterns = [

path('admin/', admin.site.urls),
path('', include('shopping.urls')),
 re_path(r'^media/(?P<path>.*)$', serve,{'document_root':       settings.MEDIA_ROOT}), 
re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), 

]

и settings.py

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

STATIC_URL= "/static/"

STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')

MEDIA_ROOT= os.path.join(BASE_DIR, "media")

MEDIA_URL="/media/"

The url(…) function [Django-doc] has been removed since in favor of the re_path(…) function [Django-doc] You can find this in the release notes [Django-doc].

Таким образом, вы должны удалить url из импорта, так:

from django.urls import path, include, re_path  # no url

Я бы настоятельно советовал вам использовать одну и ту же версию Django в разработке и в продакшене, так как, вероятно, многие другие функции будут (в конечном итоге станут) устаревшими, и это затруднит отладку на продакшен-сервере.


Note: You should not use Django's functionality to serve media files or static files in production. The serve(…) function [Django-doc] is inefficient and likely unsafe. The Django documentation explains how to serve media and static files through Nginx, Apache and other mechanisms that are optimized to serve static content. Especially since these can work with caches, and will omit a lot of logic that Django uses.

Вернуться на верх