1024programmer Java Using static files in Django template-UsingstaticfilesinaDjangotemplate

Using static files in Django template-UsingstaticfilesinaDjangotemplate

I’m trying to get a file that’s in my media directory to appear on an HTML template. I’m using the “Tango with Django” book as a tutorial.

I want a file in my media directory to appear on an HTML template. I’m using the “Django” book as a tutorial.

Here is my settings.py:

This is my settings.py:

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

Here is views.py:

This is views.py:

 def about(request):

     return render(request, 'rango/about.html', )
 

And my about.html template:

And mine. html template:


 {%load staticfiles%}


    
    


 

This is the about page

cats are funny Index

I know I must be missing something very obvious, but can’t figure it out for the life of me!

I know I must be missing something obvious, but I can never figure it out!

1 solution

#1


2

The {{MEDIA_URL}} tag is deprecated. Use the {% get_media_prefix %} tag, instead.

The {MEDIA_URL} tag is deprecated. Instead, use the {% get_media_prefix %} tag.

cats are funny
 

From the documentation:

From the documentation:

Similar to the get_static_prefix, get_media_prefix populates a template variable with the media prefix MEDIA_URL.

Similar to get_static_prefix, get_media_prefix populates template variables with the media prefix MEDIA_URL.

When rendered, that src attribute will be equivalent to /media/cat.jpg. You may want to consider using STATIC_ROOT in your settings.py, instead, along with the {% static %} tag:

When rendering, the src attribute will be equal to /media/cat.jpg. You may want to consider using STATIC_ROOT in your settings. In contrast to the {% static %} tag, py:

cats are funny
 

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/754398

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索