problem in loading media files into templates

巧了我就是萌 提交于 2020-07-10 07:07:31

问题


My django project is searching for images in /profile/<pk>/myapp/profile_pics/images.jpg instead of myapp/profile_pics/images.jpg

similar to this question image isn't uploaded to media root using Django

settings.py -

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

urls.py -

urlpatterns = [
    
    path('profile/<int:pk>/', views.profile, name='profile'),
]

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

views.py-

def profile(request, pk):
    user = get_object_or_404(User, pk=pk)
    return render(request, 'myapp/profile.html',{'account': user})

Where's the problem?

来源:https://stackoverflow.com/questions/62780329/problem-in-loading-media-files-into-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!