gpt4 book ai didi

python - 属性错误: 'module' object has no attribute 'views'

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:25 25 4
gpt4 key购买 nike

我遇到了一个错误,

url(r'^media/(?P<path>.*)$',django.views.static.serve, {'document_root': settings.MEDIA_ROOT})
AttributeError: 'module' object has no attribute 'views'

urls.py

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('accounts.urls')),
url(r'^api/', include('UserToken.urls')),
url(r'^accounts/', include('accounts.urls', namespace='accounts')),
url(r'^ResultJSON/', include('ResultJSON.urls')),
url(r'^api/1.0/', include('accounts.api_urls', namespace='api')),
url(r'^api/1.0/login/', include('accounts.apitoken_urls', namespace='apilogin')),

] +static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

当我添加 +static(settings.MEDIA_URL ~ 之前,我的应用程序运行良好。所以,我不知道如何解决这个问题。

现在,当用户登录我的应用程序时,我正在制作序列化器。

在settings.py中,我写了

MEDIA_ROOT = os.path.join(BASE_DIR, 'image')
MEDIA_URL = '/image/'

最佳答案

大概应该像 urlpatterns 之后的那样:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

if settings.DEBUG == True:
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

关于python - 属性错误: 'module' object has no attribute 'views' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42186422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com