我只是在heroku上托管我的django项目,它正在获得内部服务器错误


2022-07-11T09:25:52.180154+00:00 app[web.1]: from django.urls import path, include,re_path,url
2022-07-11T09:25:52.180154+00:00 app[web.1]: ImportError: cannot import name 'url' from 'django.urls' (/app/.heroku/python/lib/python3.10/site-packages/django/urls/__init__.py)
2022-07-11T09:25:52.180154+00:00 app[web.1]: 
2022-07-11T09:25:52.180154+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2022-07-11T09:25:52.180154+00:00 app[web.1]: 
2022-07-11T09:25:52.180155+00:00 app[web.1]: Traceback (most recent call last):
2022-07-11T09:25:52.180155+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
2022-07-11T09:25:52.180155+00:00 app[web.1]: response = get_response(request)
2022-07-11T09:25:52.180158+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/whitenoise/middleware.py", line 60, in __call__
2022-07-11T09:25:52.180158+00:00 app[web.1]: response = self.get_response(request)
2022-07-11T09:25:52.180158+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
2022-07-11T09:25:52.180158+00:00 app[web.1]: response = response_for_exception(request, exc)
2022-07-11T09:25:52.180159+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 139, in response_for_exception
2022-07-11T09:25:52.180159+00:00 app[web.1]: response = handle_uncaught_exception(
2022-07-11T09:25:52.180159+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 183, in handle_uncaught_exception
2022-07-11T09:25:52.180159+00:00 app[web.1]: callback = resolver.resolve_error_handler(500)
2022-07-11T09:25:52.180160+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 710, in resolve_error_handler
2022-07-11T09:25:52.180160+00:00 app[web.1]: callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
2022-07-11T09:25:52.180160+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
2022-07-11T09:25:52.180160+00:00 app[web.1]: res = instance.__dict__[self.name] = self.func(instance)
2022-07-11T09:25:52.180160+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
2022-07-11T09:25:52.180160+00:00 app[web.1]: return import_module(self.urlconf_name)
2022-07-11T09:25:52.180161+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module  
2022-07-11T09:25:52.180161+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-07-11T09:25:52.180162+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-07-11T09:25:52.180163+00:00 app[web.1]: File "/app/myweb1/urls.py", line 17, in <module>
2022-07-11T09:25:52.180163+00:00 app[web.1]: from django.urls import path, include,re_path,url
2022-07-11T09:25:52.180163+00:00 app[web.1]: ImportError: cannot import name 'url' from 'django.urls' (/app/.heroku/python/lib/python3.10/site-packages/django/urls/__init__.py)
2022-07-11T09:25:52.180164+00:00 app[web.1]:
2022-07-11T09:25:52.180164+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2022-07-11T09:25:52.180164+00:00 app[web.1]:
2022-07-11T09:25:52.180164+00:00 app[web.1]: Traceback (most recent call last):
2022-07-11T09:25:52.180164+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
2022-07-11T09:25:52.180165+00:00 app[web.1]: response = get_response(request)
2022-07-11T09:25:52.180165+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/utils/deprecation.py", line 134, in __call__
2022-07-11T09:25:52.180165+00:00 app[web.1]: response = response or self.get_response(request)
2022-07-11T09:25:52.180165+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
2022-07-11T09:25:52.180166+00:00 app[web.1]: response = response_for_exception(request, exc)
2022-07-11T09:25:52.180166+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 139, in response_for_exception
2022-07-11T09:25:52.180166+00:00 app[web.1]: response = handle_uncaught_exception(
2022-07-11T09:25:52.180167+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 183, in handle_uncaught_exception
2022-07-11T09:25:52.180167+00:00 app[web.1]: callback = resolver.resolve_error_handler(500)
2022-07-11T09:25:52.180167+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 710, in resolve_error_handler
2022-07-11T09:25:52.180168+00:00 app[web.1]: callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
2022-07-11T09:25:52.180168+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
2022-07-11T09:25:52.180168+00:00 app[web.1]: res = instance.__dict__[self.name] = self.func(instance)
2022-07-11T09:25:52.180169+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
2022-07-11T09:25:52.180169+00:00 app[web.1]: return import_module(self.urlconf_name)
2022-07-11T09:25:52.180169+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module  
2022-07-11T09:25:52.180170+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-07-11T09:25:52.180170+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-07-11T09:25:52.180170+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-07-11T09:25:52.180170+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-07-11T09:25:52.180170+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-07-11T09:25:52.180171+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-07-11T09:25:52.180171+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-07-11T09:25:52.180174+00:00 app[web.1]: File "/app/myweb1/urls.py", line 17, in <module>
2022-07-11T09:25:52.180174+00:00 app[web.1]: from django.urls import path, include,re_path,url
2022-07-11T09:25:52.180174+00:00 app[web.1]: ImportError: cannot import name 'url' from 'django.urls' (/app/.heroku/python/lib/python3.10/site-packages/django/urls/__init__.py)
2022-07-11T09:25:52.180174+00:00 app[web.1]:
2022-07-11T09:25:52.180174+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2022-07-11T09:25:52.180175+00:00 app[web.1]:
2022-07-11T09:25:52.180175+00:00 app[web.1]: Traceback (most recent call last):
2022-07-11T09:25:52.180175+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 136, in handle
2022-07-11T09:25:52.180175+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2022-07-11T09:25:52.180175+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2022-07-11T09:25:52.180175+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2022-07-11T09:25:52.180176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 132, in __call__
2022-07-11T09:25:52.180176+00:00 app[web.1]: response = self.get_response(request)
2022-07-11T09:25:52.180176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/base.py", line 140, in get_response
2022-07-11T09:25:52.180176+00:00 app[web.1]: response = self._middleware_chain(request)
2022-07-11T09:25:52.180176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 57, in inner
2022-07-11T09:25:52.180176+00:00 app[web.1]: response = response_for_exception(request, exc)
2022-07-11T09:25:52.180177+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 139, in response_for_exception
2022-07-11T09:25:52.180177+00:00 app[web.1]: response = handle_uncaught_exception(
2022-07-11T09:25:52.180177+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 183, in handle_uncaught_exception
2022-07-11T09:25:52.180177+00:00 app[web.1]: callback = resolver.resolve_error_handler(500)
2022-07-11T09:25:52.180178+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 710, in resolve_error_handler
2022-07-11T09:25:52.180178+00:00 app[web.1]: callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
2022-07-11T09:25:52.180178+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__
2022-07-11T09:25:52.180178+00:00 app[web.1]: res = instance.__dict__[self.name] = self.func(instance)
2022-07-11T09:25:52.180178+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
2022-07-11T09:25:52.180178+00:00 app[web.1]: return import_module(self.urlconf_name)
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module  
2022-07-11T09:25:52.180179+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-07-11T09:25:52.180179+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-07-11T09:25:52.180180+00:00 app[web.1]: File "/app/myweb1/urls.py", line 17, in <module>
2022-07-11T09:25:52.180180+00:00 app[web.1]: from django.urls import path, include,re_path,url
2022-07-11T09:25:52.180180+00:00 app[web.1]: ImportError: cannot import name 'url' from 'django.urls' (/app/.heroku/python/lib/python3.10/site-packages/django/urls/__init__.py)
2022-07-11T09:25:52.180301+00:00 app[web.1]: 10.1.35.183 - - [11/Jul/2022:09:25:52 +0000] "GET / HTTP/1.1" 500 0 "-" "-"

这里我得到了错误。我的urls.py文件

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/"

url(…)函数[Django-doc]从django-4.0开始被移除,取而代之的是re_path(…)function[Django-doc]你可以在发行说明[Django-doc]中找到。

因此,您应该从导入中删除url,因此:
from django.urls import path, include, re_path  #no url

强烈建议您在开发和生产中使用相同的Django版本,因为很可能有许多其他特性(最终)会被弃用,因此这使得在生产服务器上调试变得困难。


注意:在生产环境中,你不应该使用Django的功能来提供媒体文件或静态文件。的serve(…)函数[Django-doc]是低效且不安全的。Django文档解释了如何通过NginxApache和其他优化的机制来提供媒体和静态文件提供静态内容。特别是因为它们可以与缓存一起工作,并且会忽略Django使用的许多逻辑。

相关内容

  • 没有找到相关文章

最新更新