How to show image(static) files.

37 views
Skip to first unread message

Edit Sensei

unread,
May 2, 2023, 10:19:15 AM5/2/23
to django...@googlegroups.com
How to show image(static) files in django HTML 
Actually i was created scan QRcode . I want to show QRcode. If it code is true then next page..
Else code false then error...

William Nash (Bill)

unread,
May 2, 2023, 10:43:58 AM5/2/23
to Django users
Try this.  I'm still learning myself

In your HTML file, you can use the img tag to display the image.

<img src="{% static 'images/your_image_name.jpg' %}" alt="Your Image">

To check if the QR code is true or false, you can use Django's views.py file. In your views.py file, write a function that will check the validity of the QR code. The function should redirect the user to the next page if the QR code is valid. The function should return an error message if the QR code is invalid. 

from django.shortcuts import render, redirect

def scan_qr_code(request):
    if qr_code_is_valid:
        return redirect('next_page')
    else:
        error_message = 'Invalid QR code'
        return render(request, 'error.html', {'error_message': error_message})

Byansi Samuel

unread,
May 2, 2023, 12:01:12 PM5/2/23
to django...@googlegroups.com
Your code is not wrong but just add "url" after static. Then it will work

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7ad0255d-34d4-466c-aef2-2eb73f98186dn%40googlegroups.com.

ivan harold

unread,
Aug 17, 2023, 2:30:25 PM8/17/23
to Django users
Reply all
Reply to author
Forward
0 new messages