问题
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