Django and SQLite3 doesn't work

614

Solved in comments by OP:

I've fixed this issue by running sudo python manage.py runserver instead of python manage.py runserver.

Share:
614

Related videos on Youtube

Rahul Sharma
Author by

Rahul Sharma

Updated on September 18, 2022

Comments

  • Rahul Sharma
    Rahul Sharma over 1 year

    In my Django Application I am creating Barcodes of an Object and up until then it works fine, the PNGs are created perfectly but How can I arrange them in a PDF in a 7x2 Grid such that they can be printed?

    Is there any Library which takes the images as input and create a pdf with these images?

    Here's the code:

    class GrnBarcodes(APIView):
        permission_classes = (permissions.IsAuthenticated,)
    
        def get(self, request, *args, **kwargs):
            pk = self.kwargs['pk']
            grn = Grn.objects.filter(pk=pk)[0]
            grn_prod = grn.items.all()
            items = []
            for i in grn_prod:
                for j in range(i.item_quantity):
                    items.append("YNT9299"+str(pk)+str(i.item.short_code)+str(j+1))
    
            zpl_img = []
            for i in items:
                barcode = get_barcode(value=i, width=650)
                a = barcode.save(formats=['PNG'], fnRoot=str(i))
                with open(a, 'rb') as image:
                    img = image.read()
                    grf = GRF.from_image(img, 'YNT')
                grf.optimise_barcodes()
                # os.remove(a)
                zpl_img.append(grf.to_zpl())
    
    
            return Response(zpl_img)
    

    The grid that I have to place these images looks like this:

    enter image description here

    Drive Link to images:

    https://drive.google.com/drive/folders/1YDdmiePc3qQ0DW_UZFigNClCPs89ITGz?usp=sharing

    • Timo
      Timo almost 9 years
      It looks like you compiled Python yourself based on the path. You probably forgot to install sqlite development files before compilation or missed some flags to make sure sqlite modules are comiled and included. Check the compilation docs for Python to see what you did wrong.
    • letsdisappear
      letsdisappear almost 9 years
      @Timo I've fixed this issue by typing 'sudo python manage.py runserver' instead of 'python manage.py runserver'. Would you explain me why? I don't get it
    • Tim
      Tim almost 9 years
    • akpp
      akpp over 4 years
      I my case it happened on Ubuntu 18.04 python version 3.7.3 and pyenv. I installed system requirements pyenv wiki and tried to use previous advises 'sudo apt-get install python-sqlite' But nothing did not helped me except switching to previous version of python 3.6.8
  • Amir
    Amir about 8 years
    ohh this is horrible. sudo is the main calprit
  • Rahul Sharma
    Rahul Sharma over 3 years
    Hi Yuri! Thanks for answering, I tried the code but can you please explain the code and it's variable such that I can make changes like increase the distance between barcodes vertically and horizontally and change the margins ?
  • Yuri Nudelman
    Yuri Nudelman over 3 years
    I added some more comments have a look
  • Rahul Sharma
    Rahul Sharma over 3 years
    Hi Yuri! I have been struggling since yesterday to make it a 7x2 grid and tried every changes in width and height and failed.. My image pixel is ` barcode = get_barcode(value=i, width=600), so how can I set gen_flow_layout_pdf(r'example2.pdf', 1300, 1500, img, resolution=300)` such that 7x2 is created ? Currently I have 15 Images, for a better understanding I have attached a drive link of images. Please Help!
  • Rahul Sharma
    Rahul Sharma over 3 years
    Also mx and my doesn't seem to have any impact on the pdf created, how do they work ?
  • Yuri Nudelman
    Yuri Nudelman over 3 years
    See the edit. I explained the principle. This principle can also be easily scripted, if you need to, I suggest you do it for some practice, it never hurts.
  • Faisal Manzer
    Faisal Manzer over 3 years
    You can use this in Django templates and for the image, you can use Base64 images you are not saving barcodes to any storage.