Python-Django app to create & display barcodes
Code from a tutorial by Pyplane - see ? Inspiration below
Note: to open web links in a new window use: ctrl+click on link
⚡ Python Django BarCode
Table of contents
General info
Screenshots
Technologies
Setup
Code Examples
Features
Status & To-do list
Inspiration
Contact
Django framework admin dashboard lets user specify barcode fields. These are converted into a barcode using the python-barcode
library function and displayed.
Python v3 programming language
Django v3 server-side web framework
python-barcode v0.13.1 to create barcode. Supports barcode formats: EAN-8, EAN-13, EAN-14, UPC-A, JAN, ISBN-10, ISBN-13, ISSN, Code 39, Code 128, PZN
Pillow v8 Python Imaging Library (Fork)
Install Python
Install pip
Install Django by typing pip install Django
Run django-admin startproject barcode_proj
to create a new project ref. docs
Open barcode_proj
in VS Code
Run python manage.py startapp products
to create Python module
Add code
Run pip freeze
to see list of modules installed. Ref. Docs
Run python manage.py makemigrations
for changes to models etc.
Run python manage.py migrate
to migrate the migration files.
To add a superuser Run python manage.py createsuperuser --username=joe [email protected]
Ref. Docs
Run python manage.py runserver
to run server on port 8000 and open /admin console
extract from products/models.py
by Pyplane showing Product class with fields, a string representation of the product and the bar code
class Product(models.Model):name = models.CharField(max_length=200)barcode = models.ImageField(upload_to='images/', blank=True)country_id = models.CharField(max_length=1, null=True)manufacturer_id = models.CharField(max_length=6, null=True)product_id = models.CharField(max_length=5, null=True)def __str__(self):return str(self.name)def save(self, *args, **kwargs):EAN = barcode.get_barcode_class('ean13')ean = EAN(f'{self.country_id}{self.manufacturer_id}{self.product_id}', writer=ImageWriter())buffer = BytesIO()ean.write(buffer)self.barcode.save(f'{self.name}.png', File(buffer), save=False)return super().save(*args, **kwargs)
Django inbuilt packages - admin dashboard
Status: Working
To-do: Comment code, complete readme. Change server config so it shows admin panel right away (so not necessary to add /admin
to server path)
Pyplane: Youtube: Django barcode generator | How to create barcodes in Django
python-barcode documentation
Medium: Shankar Jha: What makes Django cool?
N/A
Repo created by ABateman, email: [email protected]