Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello I am working on a Social Media Page where Users can upload Images.

The uploaded Files are in my BLOG Folder, where also my Feed.html is placed where the Content is displayed.

But I want to show the uploaded Files to my Profile.hmtl as well, the File is on the USERS Folder.

For example:

<img class="image-style" src="{{ post.file.url }}">


this is the code that shows the Image Content, but when I use this on my /USERS/Profile.html it doesn't show the content, because the url is on the BLOG Folder, how can I adjust the code to get the information from the Blog Folder?

Thank you for every Answer.

What I have tried:

I tried something like:

<img class="image-style" src="{{ blog/post.file.url }}">


but that of course didn't work.

I tried to get the views.py and urls.py from USERS to BLOG but it just mixes up everything and doesn't work well.
Posted
Updated 16-Jul-23 22:28pm

1 solution

You need to adjust the image source path to point to the correct location relative to your /USERS/Profile.html file, what you are looking for is '../' which will navigate up one folder.

I am assuming this is what your folder/file structure looks like -
markdown
BLOG/
    - Feed.html
    - images/
        - image1.jpg
        - image2.jpg
- USERS/
    - Profile.html


Based on structure, your code will be -
HTML
<img class="image-style" src="../BLOG/images/image1.jpg">


What the code does is, go from the current folder - 'USERS' with file 'Profile.html' open, up one folder to - 'BLOG', down one folder into - 'images' and then the actual image file.
 
Share this answer
 
v4
Comments
Berk Ö. 17-Jul-23 14:26pm    
well my images are being uploaded to the database, so i can't just select an Image directly, but have to use {{ post.file.url }} for it to be selected. Is there a way I can make that command {{ post.file.url }} directed to BLOG, because the Python for it is on the BLOG Folder?
Andre Oosthuizen 18-Jul-23 3:59am    
Yes, just change the source accordingly -
<img class="image-style" src="../BLOG/post.file.url">
Berk Ö. 18-Jul-23 13:42pm    
It didn't work, it didn't display the images, but still thank you for you're help.
Andre Oosthuizen 19-Jul-23 4:28am    
Have you tried -
<img class="image-style" src="{{ ../blog/post.file.url }}">


Also show me what 'post.file.url' returns in the url?
Berk Ö. 19-Jul-23 14:52pm    
Yes i tried the code. It gives me back this Error:

TemplateSyntaxError at /user/21/
Could not parse the remainder: '/blog/post.file.url' from '../blog/post.file.url'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900