GithubHelp home page GithubHelp logo

dprog-philippe-docourt / django-qr-code Goto Github PK

View Code? Open in Web Editor NEW
165.0 8.0 46.0 847 KB

An application that provides tools for displaying QR codes on your Django site.

License: BSD 3-Clause "New" or "Revised" License

Python 87.10% HTML 10.75% Shell 1.73% Dockerfile 0.41%

django-qr-code's Introduction

Django QR Code

Latest PyPI version Downloads Documentation Status Build and Test Maintainability

This is an application that provides tools for displaying QR codes on your Django site.

This application depends on the Segno QR Code generator library.

This app makes no usage of the Django models and therefore do not use any database.

Only Python >= 3.10 is supported.

Features

  • Generate QR codes as embedded SVG or PNG images in HTML templates.
  • Customize QR codes with various parameters (size, error correction, border, etc.).
  • Generate URLs for QR code images.
  • Support for specific application QR codes (e.g., contact info, Wi-Fi config).
  • Cache QR code images for performance.
  • Secure QR code image serving with URL protection and user authentication.

Installation

Binary Package from PyPi

In order to use this app in a Django project, the simplest way is to install it from PyPi:

pip install django-qr-code

From the Source Code

In order to modify or test this app you may want to install it from the source code.

Clone the GitHub repository and install dependencies:

git clone https://github.com/dprog-philippe-docourt/django-qr-code
pip install -r requirements.txt -r requirements-dev.txt
python manage.py collectstatic --no-input

Usage

Start by adding qr_code to your INSTALLED_APPS setting like this:

INSTALLED_APPS = (
    # ...,
    'qr_code',
)

You need to load the tags provided by this app in your template with:

{% load qr_code %}

The source code on GitHub contains a simple demo app. Please check out the templates folder for an example of template, and the setting and urls files for an example of configuration and integration.

Example: Inline QR Code

Generate a simple QR code:

{% qr_from_text "Hello World!" size="T" %}

Example: URL QR Code

Generate a URL for a QR code image:

<img src="{% qr_url_from_text "Hello World!" %}" alt="Hello World!">

Advanced Usage of Tags

Refer to the official documentation for tags for more detailed information and advanced usage examples.

Demo Application

If you want to try this app, you may want to use the demo application shipped alongside the source code.

Get the source code from GitHub, follow the installation instructions above, and run the runserver command of Django:

python manage.py runserver

The demo application should be running at http://127.0.0.1:8000/qr-code-demo/.

If you have Docker Compose installed, you can simply run the following from a terminal (this will save you the burden of setting up a proper python environment):

cd scripts
./run-demo-app.sh

The demo application should be running at http://127.0.0.1:8910/qr-code-demo/.

Generating Image Object Representing a QR Code

If you do not want to use Django tags for rendering QR code in a template, you can simply use the API in your code. For instance, qr_code.qrcode.maker.make_qr_code_image will return bytes representing an image according to the image_format passed in the qr_code_options parameter.

Refer to the official API documentation for more detailed information.

Testing

Get the source code from GitHub, follow the installation instructions above, and run the test command of Django:

python manage.py test

This will run the test suite with the locally installed version of Python and Django.

If you have Docker Compose installed, you can simply run the following from a terminal (this will save you the burden of setting up a proper python environment):

cd scripts
./run-tests.sh

This will run the test suite with all supported versions of Python and Django. The test results are stored within tests_result folder.

Projects Using this App

This app is used in the following projects:

  • MyGym Web: a web platform for managing sports clubs. The QR codes are used for importing members' contact information in a phone book.
  • Gymna-Score: a web platform for entering scores during gymnastics competitions organized by the Association Cantonale Jurassienne de Gymnastique (ACJG). The QR codes are used to provide an easy way for the public to follow an ongoing competition. They are also used to authenticate judges that need to enter scores.
  • AC-Ju: a website that generates digital vouchers that can be redeemed at affiliate merchants.

django-qr-code's People

Contributors

dependabot[bot] avatar georgesk avatar heuer avatar mapreri avatar philippe-docourt avatar piotrszyma avatar vlt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-qr-code's Issues

Add support for Jinja2 templates

Was curious if you would be interested in having Jinja2 support added to this module?

I wouldn't mind making an attempt at adding an internal contrib module to add django-jinja style template tags and functions.

It could also possibly work as an external module if you aren't interested in adding support within this one.

Generate qrcode to go to a url in app

Hello! I want to generate a qr code that will redirect the users to the template html in django app.
I tried using the qr_url_from_text and change it to the link but ends up with an error.

Hope you can help! Thanks!

access qrcode image when not authenticated

Hello ,
I started to use django-qr-code in my project for users one to one related User profile, everything works great for me , except that
The profile template which display the qrcode created for the current user if i do "Copy image location" although its complicated link still i can access it from another browser session or remote location by copy past the image location.
The profile template page is password protected using LoginRequiredMixin
My question might missed that part, how can avoid such condition is there a way to restrict qrcode access only with authenticated users?
Please advice
Thanks

My model related that qr is created from is as follows

class OtpProfile(models.Model):

	DOMAIN_NAME = config('DOMAIN_NAME')
	
	user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)

	#qr_creation = otp_google_auth(secret, user)
	otp_code = models.CharField(max_length=200)
	user_auth_url = models.CharField(max_length=300)
	

	def __str__(self):
		return str(self.user)


	def save(self, *args, **kwargs):
		secret = pyotp.random_base32()
		self.otp_code = secret
		googleauth = pyotp.totp.TOTP(secret).provisioning_uri(name=str(self.user) + self.DOMAIN_NAME, issuer_name='Secure Dalet')
		self.user_auth_url = googleauth
		
		super().save(*args, **kwargs) 

My profile view

class UserProfileView(LoginRequiredMixin, TemplateView):
    template_name = 'user-profile.html'
    login_url = '/'
    AUTH_SRV = config('AUTH_SRV')
    BASEDN = config('BASEDN')
    SVCUSER = config('SVCUSER')
    SVCPASS = config('SVCPASS')
    DOMAIN_NAME = config('DOMAIN_NAME')

    def get_context_data(self, **kwargs):
        context = super(UserProfileView, self).get_context_data(**kwargs)
        
        profileuser = str(self.request.user) + self.DOMAIN_NAME
        current_user = self.request.user
        UserProfileData  = LdapOpertions(self.AUTH_SRV, self.BASEDN, self.SVCUSER, self.SVCPASS, profileuser)
        context['profile_info'] = UserProfileData.query_user_attrib()
        #print(context)
        context['usr_reevts'] = PassEvents.objects.filter(user_related_event__exact=profileuser)
        context['otp_obj'] = OtpProfile.objects.filter(user__exact=current_user)
        print(context)
        return context

the template showing the qrcode

{% if otp_obj %}
             {% for objotp in otp_obj %}
             <p>{{objotp.user}}</p>
             {% qr_from_text objotp.user_auth_url size=8 border=6 image_format="png" error_correction="L" %}
            
             {% endfor %}
             {% endif %}

error when generating qr code from lazy text.

{% qr_code reverse_lazy_url %}

I think

    encoded_text = str(base64.urlsafe_b64encode(bytes(text, encoding='utf-8')), encoding='utf-8')

should be

    encoded_text = str(base64.urlsafe_b64encode(bytes(str(text), encoding='utf-8')), encoding='utf-8')

Test errors when run in a 32 bit system

Hi,

when I tried to run the testsuite on a i386 system (but the same happened on armhf, but not arm64, so my guess is that it's bitness-related), I had the following errors:

python3.8 manage.py test
System check identified no issues (0 silenced).
....Unknown image format: invalid-image-format
.Testing template: {% qr_url_for_email "[email protected]" image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_tel  "+41769998877" image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_sms  "+41769998877" image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_geolocation latitude=586000.32 longitude=250954.19 altitude=500 image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_geolocation coordinates=coordinates image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_google_maps latitude=586000.32 longitude=250954.19 image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_google_maps coordinates=coordinates image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_wifi wifi_config image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_wifi wifi_config image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_wifi wifi_config=wifi_config image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_contact contact_detail image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_contact contact_detail image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_contact contact_detail=contact_detail image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_youtube "J9go2nj6b3M" image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_youtube video_id image_format="png" size="t" cache_enabled=False %}
Testing template: {% qr_url_for_google_play "ch.admin.meteoswiss" image_format="png" size="t" cache_enabled=False %}
.Testing template: {% qr_url_for_email "[email protected]" image_format="svg" cache_enabled=False %}
FTesting template: {% qr_for_email "[email protected]" image_format="png" size="t" %}
Testing template: {% qr_for_tel  "+41769998877" image_format="png" size="t" %}
Testing template: {% qr_for_sms  "+41769998877" image_format="png" size="t" %}
Testing template: {% qr_for_geolocation latitude=586000.32 longitude=250954.19 altitude=500 image_format="png" size="t" %}
Testing template: {% qr_for_geolocation coordinates=coordinates image_format="png" size="t" %}
Testing template: {% qr_for_google_maps latitude=586000.32 longitude=250954.19 image_format="png" size="t" %}
Testing template: {% qr_for_google_maps coordinates=coordinates image_format="png" size="t" %}
Testing template: {% qr_for_wifi wifi_config image_format="png" size="t" %}
Testing template: {% qr_for_wifi wifi_config image_format="png" size="t" %}
Testing template: {% qr_for_wifi wifi_config=wifi_config image_format="png" size="t" %}
Testing template: {% qr_for_contact contact_detail image_format="png" size="t" %}
Testing template: {% qr_for_contact contact_detail image_format="png" size="t" %}
Testing template: {% qr_for_contact contact_detail=contact_detail image_format="png" size="t" %}
Testing template: {% qr_for_youtube "J9go2nj6b3M" image_format="png" size="t" %}
Testing template: {% qr_for_youtube video_id image_format="png" size="t" %}
Testing template: {% qr_for_google_play "ch.admin.meteoswiss" image_format="png" size="t" %}
.Testing template: {% qr_for_email "[email protected]" image_format="svg" %}
FTesting template: {% qr_from_text "/%+¼@#=<>àé" image_format="png" error_correction="L" %}
Testing template: {% qr_from_text "/%+¼@#=<>àé" image_format="png" error_correction="M" %}
Testing template: {% qr_from_text "/%+¼@#=<>àé" image_format="png" error_correction="Q" %}
Testing template: {% qr_from_text "/%+¼@#=<>àé" image_format="png" error_correction="H" %}
.Testing PNG with size t
Testing PNG with size T
Testing PNG with size s
Testing PNG with size S
Testing PNG with size None
Testing PNG with size -1
Testing PNG with size 0
Testing PNG with size m
Testing PNG with size M
Testing PNG with size l
Testing PNG with size L
Testing PNG with size h
Testing PNG with size H
Testing PNG with size 6
Testing PNG with size 6
Testing PNG with size 8
Testing PNG with size 8
Testing PNG with size 10
Testing PNG with size 10
.Testing PNG with version None
Testing PNG with version -1
Testing PNG with version 0
Testing PNG with version 41
Testing PNG with version -1
Testing PNG with version 0
Testing PNG with version 41
Testing PNG with version blabla
Testing PNG with version 1
Testing PNG with version 1
Testing PNG with version 2
Testing PNG with version 2
Testing PNG with version 4
Testing PNG with version 4
.Testing template: {% qr_from_text "/%+¼@#=<>àé" image_format="svg" error_correction="L" %}
FTesting SVG with size t
Unknown image format: invalid-format-name
FTesting SVG with version None
Unknown image format: invalid-format-name
FTesting PNG URL with error correction: L
Testing PNG URL with error correction: M
Testing PNG URL with error correction: Q
Testing PNG URL with error correction: H
.	 - cache_enabled=True, url_signature_enabled=True
	 - cache_enabled=True, url_signature_enabled=False
	 - cache_enabled=True, url_signature_enabled=None
	 - cache_enabled=False, url_signature_enabled=True
	 - cache_enabled=False, url_signature_enabled=False
	 - cache_enabled=False, url_signature_enabled=None
	 - cache_enabled=None, url_signature_enabled=True
	 - cache_enabled=None, url_signature_enabled=False
	 - cache_enabled=None, url_signature_enabled=None
.	 - cache_enabled=True, url_signature_enabled=True
	 - cache_enabled=True, url_signature_enabled=False
	 - cache_enabled=True, url_signature_enabled=None
	 - cache_enabled=False, url_signature_enabled=True
	 - cache_enabled=False, url_signature_enabled=False
	 - cache_enabled=False, url_signature_enabled=None
	 - cache_enabled=None, url_signature_enabled=True
	 - cache_enabled=None, url_signature_enabled=False
	 - cache_enabled=None, url_signature_enabled=None
.	 - cache_enabled=True, url_signature_enabled=True
	 - cache_enabled=True, url_signature_enabled=False
	 - cache_enabled=True, url_signature_enabled=None
	 - cache_enabled=False, url_signature_enabled=True
	 - cache_enabled=False, url_signature_enabled=False
	 - cache_enabled=False, url_signature_enabled=None
	 - cache_enabled=None, url_signature_enabled=True
	 - cache_enabled=None, url_signature_enabled=False
	 - cache_enabled=None, url_signature_enabled=None
.Testing SVG URL with error correction: L
Unknown image format: invalid-format-name
F	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F.	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F	 - cache_enabled=True, url_signature_enabled=True, user=None
Unknown image format: invalid-format-name
F....
======================================================================
FAIL: test_demo_sample_urls_in_svg_format (qr_code.tests.tests.TestQRForApplications)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 609, in test_demo_sample_urls_in_svg_format
    self.assertEqual(source_image_data, ref_image_data)
AssertionError: '<?xm[221 chars]d="M 16.2 39.6 L 16.2 41.4 L 18.0 41.4 L 18.0 [16102 chars]svg>' != '<?xm[221 chars]d="M 34.2 45 L 34.2 46.8 L 36.0 46.8 L 36.0 45[16102 chars]svg>'
Diff is 32712 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_demo_samples_embedded_in_svg_format (qr_code.tests.tests.TestQRForApplications)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 586, in test_demo_samples_embedded_in_svg_format
    self.assertEqual(source_image_data, ref_image_data)
AssertionError: '<?xm[221 chars]d="M 16.2 39.6 L 16.2 41.4 L 18.0 41.4 L 18.0 [16102 chars]svg>' != '<?xm[221 chars]d="M 34.2 45 L 34.2 46.8 L 36.0 46.8 L 36.0 45[16102 chars]svg>'
Diff is 32712 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_error_correction (qr_code.tests.tests.TestQRFromTextSvgResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 429, in test_error_correction
    self.assertEqual(source_image_data, ref_image_data)
AssertionError: '<svg[177 chars]d="M 39.6 7.2 L 39.6 9.0 L 41.4 9.0 L 41.4 7.2[10480 chars]svg>' != '<svg[177 chars]d="M 28.8 14.4 L 28.8 16.2 L 30.6 16.2 L 30.6 [10480 chars]svg>'
Diff is 21429 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_size (qr_code.tests.tests.TestQRFromTextSvgResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 381, in test_size
    self.assertEqual(qr1, result)
AssertionError: '<svg[177 chars]d="M 13.2 2.4 L 13.2 3.0 L 13.8 3.0 L 13.8 2.4[9506 chars]svg>' != '<svg[177 chars]d="M 9.6 4.8 L 9.6 5.4 L 10.2 5.4 L 10.2 4.8 z[9506 chars]svg>'

======================================================================
FAIL: test_version (qr_code.tests.tests.TestQRFromTextSvgResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 411, in test_version
    self.assertEqual(qr1, result)
AssertionError: '<svg[177 chars]d="M 39.6 7.2 L 39.6 9.0 L 41.4 9.0 L 41.4 7.2[10434 chars]svg>' != '<svg[177 chars]d="M 28.8 14.4 L 28.8 16.2 L 30.6 16.2 L 30.6 [10434 chars]svg>'

======================================================================
FAIL: test_svg_error_correction (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 326, in test_svg_error_correction
    self.assertEqual(source_image_data, ref_image_data)
AssertionError: '<svg[177 chars]d="M 39.6 7.2 L 39.6 9.0 L 41.4 9.0 L 41.4 7.2[10480 chars]svg>' != '<svg[177 chars]d="M 28.8 14.4 L 28.8 16.2 L 30.6 16.2 L 30.6 [10480 chars]svg>'
Diff is 21429 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_svg_url (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_svg_with_cache_but_no_alias (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 228, in test_svg_with_cache_but_no_alias
    self.test_svg_url()
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_url_with_protection_settings_1 (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 242, in test_url_with_protection_settings_1
    self.test_svg_url()
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_url_with_protection_settings_2 (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 250, in test_url_with_protection_settings_2
    self.test_svg_url()
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_url_with_protection_settings_3 (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 259, in test_url_with_protection_settings_3
    self.test_svg_url()
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_url_with_protection_settings_4 (qr_code.tests.tests.TestQRUrlFromTextResult)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 268, in test_url_with_protection_settings_4
    self.test_svg_url()
  File "/build/django-qr-code-1.3.1/qr_code/tests/tests.py", line 189, in test_svg_url
    self.assertEqual(image_data, TestQRUrlFromTextResult._get_reference_result_for_default_svg())
AssertionError: '<?xm[217 chars]d="M 2.2 0.4 L 2.2 0.5 L 2.3 0.5 L 2.3 0.4 z M[8979 chars]svg>' != '<?xm[217 chars]d="M 1.6 0.8 L 1.6 0.9 L 1.7 0.9 L 1.7 0.8 z M[8979 chars]svg>'
Diff is 18458 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 31 tests in 1.726s

FAILED (failures=12)

I haven't debugged this in any way, but any help or hint is appreciated!

Do not use underscores in urls

In https://github.com/dprog-philippe-docourt/django-qr-code/blob/master/qr_code/urls.py, there is a hardcoded section that creates urls with underscores.

urlpatterns = [
    path('images/serve_qr_code_image/', views.serve_qr_code_image, name='serve_qr_code_image')
]

Using underscores in urls is allowed, but can be considered bad practice, see https://www.quora.com/Is-an-underscore-allowed-in-a-URL. Would you consider using hyphens here instead of underscores? Or just user serve instead of serve_qr_code_image.

Thanks for this library!

Generating an image

Apologies but I cannot understand from your documentation how to simply generate a qrcode as a png/jpg etc. without having to render a template. Is it possible?

Possible to not use templates?

I'd like to use a class-based DetailView that overrides render_to_response to serve a qr code image via FileResponse directly instead of using a template.

For example, my url pattern localhost/MY-SAVED-OBJECT will return the image saved to an ImageField on the model via FileResponse. I want an additional url pattern such as localhost/qr/MY-SAVED-OBJECT to do the same thing but with the generated qr code.

Can I use this module for doing that or should I look at the Segno library instead?

Must be something silly, but...

Following the instructions I get the local server started to check out the demo site, but what I get is the django debug screen with:

Using the URLconf defined in demo_site.urls, Django tried these URL patterns, in this order:

qr-code-demo/
qr-code/

The current path, qr_code_demo/, didn't match any of these.

Evaluate escape sequences

it seams like qr_from_text dosn't evaluate escape sequences \t for TAB, \n for ENTER

i tried this with no success

{% qr_from_text "value_of_input_1%0Avalue_of_input_2" size="m" %}
{% qr_from_text "value_of_input_1 /t Avalue_of_input_2" size="m" %}

I'm i missing something ?

thank you in advance

How to retrieve the cached static URL of QR codes

How should I go about accessing the actual image URL of the QR code that is generated? I am passing the retrieved image into Zebra BrowserPrint to be sent to a thermal printer, but it doesn't seem to play nicely with the tokenized image URL. Any ideas?

Or some direction on where I should look to create my own method that can return a URL.

Deprecation warning from pydantic 2.0.x

When I run my test cases in my django projects that uses django-qr-code I've started to get this deprecation warning since pydantic v2 was released:

/home/tomas/.local/share/virtualenvs/condaba-idd1Bo2x/lib/python3.10/site-packages/qr_code/qrcode/maker.py:32: PydanticDeprecatedSince20: The `validate_arguments` method is deprecated; use `validate_call` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
    @validate_arguments(config=PYDANTIC_CONFIG)

Clickable link to migration guide

QR Codes in email (gmail)?

When I try to include a qr_code in an email using qr_url_from_text, gmail mangles it and it's converted to something like https://ci3.googleusercontent.com/proxy/... which is broken.
Any suggestions on how to fix this?

NoReverseMatch

Followed the instructions, and added {% load qr_code %} but if I do {% qr_url_from_text %} then I get this

django.urls.exceptions.NoReverseMatch
django.urls.exceptions.NoReverseMatch: 'qr_code' is not a registered namespace

Screen Shot 2021-05-18 at 1 51 50 AM

Creating dynamic QR codes in template

Hi,

Im not sure if its possible, but it would be great if you could pass in variables from the jinja2 template into the qr code.
{% qr_from_text "Hello {{ myVariable }}" size="T" %}

To allow for generation of dynamic QR codes on the fly

Error when generating png style image.

Error

I get the following error when generating a png image from text.

save() got an unexpected keyword argument 'format'

I narrowed down the error to line 91 of maker.py in qr_code/qrcode/
img.save(stream, format=PNG_FORMAT_NAME.upper())

The img object has the method save but it does not take in the parameter format.

Possible solution

Changing the parameter format to kind as shown three lines before in line 88. Fixes the problem.
img.save(stream, kind=PNG_FORMAT_NAME.upper())

setting the border parameter is not passed to segno

The border parameter e.g. mentioned in https://github.com/dprog-philippe-docourt/django-qr-code/blob/e5d944c184759c2453da646d45bb99b512d18b95/README.md#qr-code-rendering-options is not passed to segno https://segno.readthedocs.io/en/latest/api.html#segno.QRCode.save as it is not included in

def kw_save(self):
"""Internal method which returns a dict of parameters to save a QR code.
:rtype: dict
"""
image_format = self._image_format
kw = dict(kind=image_format, scale=self._size_as_int())
# Change the color mapping into the keywords Segno expects
# (remove the "_color" suffix from the module names)
kw.update({k[:-6]: v for k, v in self.color_mapping().items()})
if image_format == 'svg':
kw['unit'] = 'mm'
scale = decimal.Decimal(kw['scale']) / 10
kw['scale'] = scale
return kw

Problem with admin page when using django-qr-code

My example app urls.py
urlpatterns = [ path('', lost.home, name='home_lost'), path('pdf_page', lost.home, include('qr_code.urls', namespace="qr_code"), name='pdf_page') ]
When i open localhost:8000/admin i get
`

Request Method: GET
http://localhost:8000/admin/
3.1.7
TypeError
'tuple' object is not a mapping
/usr/lib/python3.9/site-packages/django/urls/resolvers.py, line 486, in _populate
/usr/bin/python3
3.9.1

`
If i comment path('pdf_page', lost.home, include('qr_code.urls', namespace="qr_code"), name='pdf_page') admin page works fine?

Base64 In Emails

We are using your plugin in our Django project to email QR Codes as part of a registration process. Unfortunately, some email clients (Android in particular) do not show base64 images. Do you have any plans on providing a way for your plugin to render the images differently for this use case? CID perhaps?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.