0

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?

  • Could you add more information? You saw their question which has tons of details. What have you done for your ```settings.py``` in terms of your ```MEDIA_ROOT``` and ```MEDIA_URL``` ? – Edwin Cruz Jul 07 '20 at 17:05
  • plz post your `urls.py` and `settings.py` – JSRB Jul 07 '20 at 17:05
  • @Jonas @edwin-cruz added `urls.py`, `views.py` and `settings.py` –  Jul 08 '20 at 06:21
  • well you just want to get he user image. You can get it with the help of user object related in your profile model. – ngawang13 Jul 10 '20 at 06:21
  • @Suraj please add your template as well, so I can look into your issue – JSRB Jul 11 '20 at 05:50

0 Answers0