Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to get the current projct_id in Django
I have a view where in the options input I want to list just those users who related to the current project but I can't. I don't know how to write a query that list just these users without I use the project_id from the url. I don't want the projekt_id in the url. This is the point, where I stuck: views.py def kapcsolodasok(request, projekt_id): if request.method == 'POST': kap_bar_01 = request.POST.get('kap_bar_01') kap_bar_02 = request.POST.get('kap_bar_02') kapcsolodasok = kapcsolodasok(kap_bar_01=kap_bar_01, kap_bar_02=kap_bar_02) kapcsolodasok.save() related_users = Profile.objects.raw('SELECT stressz_profile.id, last_name, first_name, stressz_profile.projekt_id FROM stressz_projekt JOIN stressz_profile ON stressz_projekt.id = stressz_profile.projekt_id JOIN auth_user ON auth_user.id = stressz_profile.user_id WHERE stressz_projekt.id = %s', [projekt_id]) //how to replace projekt_id with the related projekt_id of the request.user context = { 'related_users': related_users, } return render(request, 'stressz/kapcsolodasok.html', context) models.py class Kapcsolodasok(models.Model): def __str__(self): return str(self.user_name) user_name = models.ForeignKey(User, on_delete=models.CASCADE, default=1) date = models.DateField(auto_now_add=True, auto_now=False, blank=True) kap_bar_01 = models.TextField(max_length=200) kap_bar_02 = models.TextField(max_length=200) class Profile(models.Model): def __str__(self): return str(self.user) user = models.OneToOneField(User, null=True, on_delete=models.CASCADE) date = models.DateField(auto_now_add=True, auto_now=False, blank=True) projekt = models.ForeignKey(Projekt, on_delete=models.CASCADE, default=3) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save() class Projekt(models.Model): def __str__(self): return str(self.projekt) projekt = models.TextField(max_length=150) date = models.DateField(auto_now_add=True, … -
Unable to import DefaultAccountAdapter from settings.py
I would like to use a custom account adapter, but as soon as I import: from allauth.account.adapter import DefaultAccountAdapter in settings.py, I get the error django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. Here is the whole error dump: (env) (base) C:\Dropbox\Parnasa\Web\drmeir>python manage.py runserver Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line utility.execute() File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\core\management\__init__.py", line 363, in execute settings.INSTALLED_APPS File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__ self._setup(name) File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\conf\__init__.py", line 69, in _setup self._wrapped = Settings(settings_module) File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\conf\__init__.py", line 170, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "c:\users\meir\anaconda3\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\Dropbox\Parnasa\Web\drmeir\mysite\settings.py", line 180, in <module> from allauth.account.adapter import DefaultAccountAdapter File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\allauth\account\adapter.py", line 17, in <module> from django.contrib.auth.models import AbstractUser File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\contrib\auth\models.py", line 3, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\contrib\auth\base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "C:\Dropbox\Parnasa\Web\drmeir\env\lib\site-packages\django\db\models\base.py", line 108, in __new__ app_config = apps.get_containing_app_config(module) File … -
Django REST Framework : How to define a viewset
Context I have two viewsets, with their own routers to automatically generate the URLs from them : ModelAViewset ModelBViewset For now, the ModelAViewset details can be retrieved through the following URL : {base_url}/model-a/<slug> With '<slug>' being the ModelA 'slug' field, as a lookup_field. Questions Is there a way to use a more explicit lookup_field value, dynamically based on the model name ? Like this : {base_url}/model-a/<model_a_slug> Note : To keep it simple in the model, I would rather like to leave the 'slug' field name of ModelA as is Based on Viewsets and Routers, is there a way to retrieve the JoinRequestViewset details through a multi lookup_fields ? With an URL like : {base_url}/model-a/<model_a_slug>/model-b/<model_b_pk> Thanks, by advance -
cart session in django
I use the session to create a shopping cart. I have a product model and a model for Variant, which I color and size my products in the Variant model. So that I can have products with different colors and sizes as well as different prices. The shopping cart I created with Session has a problem. The problem I have is that if the product has 3 different colors and each color has a different price, I have trouble displaying the price in the cart and I do not know how to act. How should I display the prices of my Variant model in the template? my Product model: class Product(models.Model): name = models.CharField(max_length=200) price = models.IntegerField(default=0) my Variant model: class Variants(models.Model): name = models.CharField(max_length=100) product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='product_var',) size = models.ForeignKey(Size, on_delete=models.CASCADE) color = models.ForeignKey(Color, on_delete=models.CASCADE) price = models.IntegerField(default=0) my session cart : CART_SESSION_ID = 'cart' class Cart: def __init__(self, request): self.session = request.session cart = self.session.get(CART_SESSION_ID) if not cart: cart = self.session[CART_SESSION_ID] = {} self.cart = cart def __iter__(self): product_ids = self.cart.keys() products = Product.objects.filter(id__in=product_ids) cart = self.cart.copy() for product in products: cart[str(product.id)]['product'] = product def add(self, product, quantity): product_id = str(product.id) if product_id not in self.cart: … -
make decorator Only the creator of Content can manipulate it
I have created Two decorator to block anyone to Access to specific content like: @method_decorator(login_required(login_url='core:login'), name='dispatch') @method_decorator(allowed_users(allowed_roles=['writer']), name='dispatch') class BookDeleteView(BSModalDeleteView): model = Book template_name = 'book/book_delete.html' success_message = 'Success: book was deleted.' success_url = reverse_lazy('core:book_list') i want to create decorator seems like this book=Book.objects.get(id=pk) if request.user==book.writer.profile.user: -
How to put data to html but to look like excel sheet in django?
I have been studying how to put data from my excel document to the html, and I have found a way but it is bit tricky, maybe you can help me with this? (Link of documentation) This is where I have been studying, but in this case it is defined what is a 'choice' and 'question'. Is there a way to do this without defining these? Tu upload random document and to load in html? -
django-mptt: How to auto select children in admin when selecting parent?
I have some troubles when selecting parent - children are not auto selected. For example when I select Cluster #2 its children (Store #1 and Store #2) are not being selected: How can I fix that? It's important because I need to create many-to-many (Deviation-Orgunit) links only with stores (with leafs). Models: from django.db import models from mptt.fields import TreeForeignKey from mptt.models import MPTTModel class Orgunit(MPTTModel): name = models.CharField( max_length=100 ) type = models.CharField( choices=[ ('MACRO', 'Макро'), ('CLUSTER', 'Кластер'), ('KUST', 'Куст'), ('STORE', 'Магазин') ], max_length=100 ) parent = TreeForeignKey( 'self', on_delete=models.CASCADE, null=True, blank=True, related_name='children' ) def __str__(self): return self.name class Deviation(models.Model): name = models.CharField(max_length=100) number = models.PositiveIntegerField(null=True) orgunits = models.ManyToManyField('orgunits.Orgunit') def __str__(self): return self.name Admin: from django.contrib import admin from deviations.forms import MyForm from deviations.models import Deviation @admin.register(Deviation) class DeviationAdmin(admin.ModelAdmin): form = MyForm Form: from django.forms import ModelForm, widgets from mptt.forms import TreeNodeMultipleChoiceField from orgunits.models import Orgunit class MyForm(ModelForm): orgunits = TreeNodeMultipleChoiceField(queryset=Orgunit.objects.all(), widget=widgets.SelectMultiple()) class Meta: model = Orgunit fields = '__all__' -
Django Serialiser get sibling records
In Django DRF, I am trying to work out I can return objects siblings. For instance, I have record B, can i return records A and B also? I can then use these to cycle blog posts for example with previous and next article links. At the moment, i am getting the current object, and then calling the database again looking for record with same parent. I am thinking there might be more efficient way. -
hide table heading if all values in table are null
I have a model form that I am displaying in a table. The form has about 40 fields broken down into 6 different tables. I have setup an if statements to not display the table elements if the field is empty in the db. This works as expected the only issue is that if all the elements are hidden the table header is still displayed. How could I hide the table header if all if the elements in that particular table are hidden. <table class="post-table"> <tr> <th class="table-header" colspan="2"> <h3>Pool Details</h3> </th> </tr> <tbody> {% if post.pool_size != '' %} <tr> <td>pool size:</td> <td>{{ post.pool_size }}</td> </tr> {% endif %} {% if post.pool_style != '' %} <tr> <td>Pool Style:</td> <td>{{ post.pool_style }}</td> </tr> {% endif %} </tbody> </table> -
Verify if user has already submitted form in Django
class Attest(models.Model): CURRENT_STATUS = ( ('yes', 'Yes'), ('no', 'No') ) owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE) value =models.CharField(max_length=200, choices=CURRENT_STATUS, default="no") created = models.DateTimeField(auto_now_add=True) id = models.UUIDField(default =uuid.uuid4, unique=True, primary_key=True, editable=False) class AttestForm(ModelForm): class Meta: model = Attest fields =['value'] widgets = { 'value': forms.RadioSelect() } {% if request.user.profile.id in ..attesters %} <p>you have already submitted your reponse!</p> {% elif request.user.is_authenticated %} <h3>1. Supplier code of conduct</h3> <p>1.1 The Supplier Code of Conduct <strong>(hereinafter referred to as the 'Code') </strong>defines minimum standards that our suppliers and anyone under their from django import forms from django.db import models import uuid from users.models import Profile # Create your models here. class Attest(models.Model): CURRENT_STATUS = ( ('yes', 'Yes'), ('no', 'No') ) owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE) value =models.CharField(max_length=200, choices=CURRENT_STATUS, default="no") created = models.DateTimeField(auto_now_add=True) id = models.UUIDField(default =uuid.uuid4, unique=True, primary_key=True, editable=False) class Meta: unique_together = [['owner']] def __str__(self): return self.value @property def attesters(self): queryset = self.attest_set.all().values_list('owner__id', flat=True) return queryset {% if request.user.profile.id in ..attesters %} I am unable to construct this statement well because im not sure the property im using is right. @property def attesters(self): Would be glad if someone could explain it better to me. >>> profile = Profile.objects.get(username="ichinexx@xxxxx.com") >>> print(profile) ichinexx@xxxxx.com" … -
Dgango( version 2.1.1) Admin panel change after upgrade to Django( version 3.2)
What did you do? Ans - I have upgrade Django(version 2.1.1) from Django(version 3.2) on Ubuntu 18.04 server What did you expect to happen? Ans - I was expecting a same admin panel but got different admin panel. As you can see in screenshot OS: Ubuntu 18.04.4 LTS (GNU/Linux 5.4.0-1048-aws x86_64) enter image description here Python: Python 3.6.9 (default, Jan 26 2021, 15:33:00) -
How to get the field of the model in Django in templates without ModelForm?
How to have an access to the field of our model without using the ModelForm object in Django ? forms.py class ChoiceAppointmentForm(forms.Form): appointment = forms.ModelChoiceField( queryset=None, widget=forms.RadioSelect) conference_method = forms.ChoiceField(choices=METHOD_CHOICES) conference_details = forms.CharField(required=False) conference_secret_code = forms.CharField(required=False) def __init__(self, *args, **kwargs): appointments = kwargs.pop('appointments') super().__init__(*args, **kwargs) self.fields['appointment'].queryset = appointments models.py class Appointment(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, null = True, on_delete = models.CASCADE) student = models.ForeignKey(Student, null=True, blank = True, on_delete=models.CASCADE) is_confirmed = models.BooleanField(default = False) date = models.DateField(null = True) choice_appointment.html <div class="fieldWrapper"> {{ form.appointment.errors }} {{ form.appointment.date }} {{ form.appointment }} </div> But It does not display the date of the appointment. I can only access the appointment object but not the date, the student, etc. How can I do ? -
Can't get CSRF token from Django REST Framework response
The problem is that the server responds with a header set-cookie with a csrftoken, but it is not displayed in the storage. The client lies at the address: https://quiz-client-app.herokuapp.com The server is located at: https://quiz-server-app.herokuapp.com Also, it is not possible to access the cookie using JS getCookie.js const csrfTokenHeader = () => { let csrftoken = null return () => { if (document.cookie && document.cookie !== '' && !csrftoken) { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.substring(0, 'csrftoken'.length + 1) === ('csrftoken' + '=')) { csrftoken = decodeURIComponent(cookie.substring('csrftoken'.length + 1)); break; } } } return { 'X-CSRFToken': csrftoken } } } How can I access the cookie? Here is server CSRF settings and example of view: settings.py ALLOWED_HOSTS = ['quiz-client-app.herokuapp.com'] # On production # CSRF CSRF_COOKIE_SAMESITE = "None" CSRF_COOKIE_HTTPONLY = False CSRF_COOKIE_SECURE = True CSRF_TRUSTED_ORIGINS = ['quiz-client-app.herokuapp.com'] CSRF_COOKIE_DOMAIN = "quiz-server-app.herokuapp.com" # SESSION SESSION_COOKIE_SAMESITE = "None" SESSION_COOKIE_HTTPONLY = False # CORS CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_HEADERS = [ "content-type", "x-csrftoken" ] CORS_ALLOW_METHODS = [ "OPTIONS", "GET", "POST", "PUT", "DELETE" ] CORS_ALLOWED_ORIGINS = [ 'https://quiz-client-app.herokuapp.com' ] views.py @method_decorator(ensure_csrf_cookie, name='post') class LoginView(APIView): def post(self, request): ... return Response() -
How to check two time period for overlap in django?
For e.g., I have two time periods 02:00:00 - 03:00:00 now I want to check that new incoming start time and end time does not fall between this range. 01:00:00 to 02:00:00 and 03:00:00 to 04:00:00 should be acceptable. -
django rest fraemwork. Save extendet user data to db
I try implement regestration endpoint fow user with additional attributes like phone_number and full_name. I implement logick for saving user data, which come from request, bit i xan't unserstand how i can save profile data, like phone_number and full_name. I have user model: class User(AbstractUser): email = models.EmailField(_('email address'), unique=True) is_verified = models.BooleanField(_('is verified by admin'), default=False) EMAIL_FIELD = 'email' USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['username'] objects = UserManager() def __str__(self): return self.email def save(self, *args, **kwargs): if not self.username: self.set_username() super().save(*args, **kwargs) def email_user(self, subject, message, from_email=None, **kwargs): """Send an email to this user.""" send_mail(subject, message, from_email, [self.email], **kwargs) def set_username(self): pass And profile model: class Profile(TimeStampedModel): STATUS = Choices( ("inactive", _("inactive")), ("active", _("active")), ("banned", _("banned")) ) user = models.OneToOneField( User, verbose_name=_('related user'), on_delete=models.CASCADE, related_name='profile', related_query_name='profile' ) description = models.TextField( _("description of user's profile"), blank=True, default='' ) status = StatusField( _("status of the user") ) birth_date = models.DateField( _("Date of birth"), validators=[ MinValueValidator( datetime.date(1910, 1, 1) ), MaxValueValidator( datetime.date.today ) ], null=True, blank=True ) avatar = models.OneToOneField( "files.Avatar", on_delete=models.SET_NULL, null=True, blank=True, related_name="profile" ) full_name = models.CharField( max_length=30, default='', blank=False ) phone_number_regex_validator = RegexValidator(regex=COMPILED_REGEXP) phone_number = models.CharField( max_length=16, default='', blank=False, validators=[phone_number_regex_validator] ) objects = ProfileQuerySet.as_manager() def __str__(self): return f"profile of … -
How to extend a Django form in template?
i have an html of base step0.html i extend it {% extends "step0.html" %} all it's good but only my Django form not extends how can I do this? -
drf_spectacular schema generation threw exception when using ./manage.py makemigrations
I get this error when I run ./manage.py makemigrations and I don't know what is causing it (no relevant logs). ERRORS: ?: (drf_spectacular.E001) Schema generation threw exception "relation "global_preferences" does not exist LINE 1: ..."preferences"."preferences" FROM "global_prefer... Django 3.2.4 DRF: 3.12 -
How to return an HttpResponse object instead of None
can you help me out through this problem?, I'm a beginner and trying to learn django..even tho i tried so many other ways but it just wont work out. i hope you can help me models.py from django.db import models from django.db.models.fields import CharField , IntegerField, EmailField class Member(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=50) email = models.EmailField() age = models.IntegerField() password = models.CharField(max_length=100,null=True) def __str__(self): return self.first_name + " " + self.last_name form.py from django.db.models import fields from django.forms import ModelForm from django import forms from .models import Member class MemberForm(forms.ModelForm): class Meta: model = Member fields = ["first_name", "last_name", "age", "email", "password"] views.py from django.shortcuts import render from .models import Member from .form import MemberForm # Create your views here. def join(request): if request.method == "POST": form = MemberForm(request.POST or None) if form.is_valid(): form.save() return render(request, "HTML/join.html",{}) else: form = MemberForm() return render(request, "HTML/base.html",{}) error The view myapp.views.join didn't return an HttpResponse object. It returned None instead. -
Determine count of object retrieval per day in django
In a model like the one below class Watched(Stamping): user = models.ForeignKey("User", null=True, blank=True, on_delete=models.CASCADE) count = models.PositiveIntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) Anytime an object is retrieved, I increment the count attribute. Now my problem is how to get the number of times an object was retrieved for each day of the week For example, WatchedObject1 will have {'Sun': 10, 'Tue': 70, 'Wed': 35} -
Compare expression with constant in CHECK constraint
I'd like to use Django's CheckConstraint to add a check constraint to a table using PostgreSQLs num_nonnulls() function, similar to this: create table foo( a text, b int, [...], check num_nonnulls(a, b, ...) = n); n is a constant but may be different for different tables (mostly it's going to be 1 but I'd like to find a general solution). This is how far I got: class Foo(models.Model): a = models.TextField(null=True) b = models.IntegerField(null=True) [...] class Meta: constraints = [ models.CheckConstraint( check=models.ExpressionWrapper( models.Func('a', 'b', function='num_nonnulls'), models.BooleanField()), name='num_nonnulls_check')] This is of course missing the step where the result of num_nonnulls() is compared to some constant integer. I tried defining a function to do this: def equals(a, b): return models.Func(a, b, template='%(expressions[0])s = %(expressions[1])s') But this doesn't work because the template argument expressions is (I think) a string (and %-template strings don't have this syntax to extract parts of an argument, I think). Where do I go from here? I'd like to find a solution that allows me to use arbitrary expressions supported by the Django ORM and also compare these expressions with other expressions or constants using an equality or inequality relation (e.g. = or <=). -
Django/Ajax/Post/ How do I send data from one table to another table
I have two tables, Exercises and Workouts. The Django models are below: name = models.CharField(max_length=200) exercises = models.ManyToManyField(Exercise, null=True) description = models.TextField(max_length=3000, default=None, blank=True, null=True) goals = models.TextField(max_length=3000, default=None, blank=True, null=True) workout_time = models.CharField(max_length=200, default=None, blank=True, null=True) difficulty = models.CharField(max_length=200, default=None, blank=True, null=True) workout_rating = models.PositiveIntegerField(default=None, blank=True, null=True) notes = models.TextField(max_length=5000, blank=True, null=True) def __str__(self): return self.name HTML form for Workouts: <forms id="workout_form" method='POST'> {{form|crispy}} <div class="row"> <div class="text-center pt-4"> <button type="button" class="btn btn-primary" id="create_workout"> Create </button> </div> </div> </forms> Above my forms, I already have a list of exercises I want to add, but this forms gives me a list of all of my exercises - which I don't want. Using Ajax, I want to send this data to Django to add to my database. I am stuck on how to add the exercises. my views.py: def workout_builder_details(request): form = WorkoutForm(request.POST or None, request.FILES or None) data = [] if request.is_ajax(): if form.is_valid(): form.save() data['name'] = form.cleaned_data.get('name') data['status'] = 'ok' return JsonResponse(data) context = { 'form': form, } return render(request, 'application/workout_builder_details.html', context) forms.py class WorkoutForm(forms.ModelForm): class Meta: model = Workout fields = ( 'name', 'exercises', 'description', 'goals', 'workout_time', 'difficulty') How can I save the data, with the exercises I've … -
Deploy Django App on subdirectory (Namecheap)
I'm Trying To deploy Django App on My Namecheap Cpanel But I want to deploy it on subdirectory Is it possible to deploy on subdirectory. And How Can I do it. (I'm new ) -
Using Select to Order my products by price,
How do you query the database when you select highest, it orders product from the most expensive price to list and vice versa. Here is my templates. I think you can see the select sort. <section class="body-section"> <!--Cleaning services--> {%for category in categories%} <section class="main-products cooler"> <div class="upper-bar"> <div> <h2>{{category.name}}</h2> </div> <div class="sortby"> <span>Sort By: <select class="sort"> <option value="highest">Highest Price</option> <option value="lowest">Lowest Price</option> </select></span> </div> </div> <hr /> <!--Single Products-wrap--> <div class="specific-product-wrap specific-product-wrap-cooler"> {% for product in category.product_set.all %} <a href="{%url 'product' product.pk%}"> <div class="specific-single-product"> <div class="product-image center"> <img class="product-image-shape" src="{{product.image.url}}" alt="adamol Distilled" /> </div> <div class="produc-descriptions"> <h4 class="specific-product-title">{{product.title}}</h4> <p class="one-line-description"></p> <p class="price">Ksh.{{product.price}}</p></a> <button data-product="{{product.id}}" data-action="add" class="AddToCart update-cart" id="addToCart update-cart">Add To Cart</button> </div> </div>` {% empty %} <p>No Product Lol</p> {%endfor%} </div> </section> Here is my model.py class Product(models.Model): image = models.ImageField(null=False, blank=False) title = models.CharField(max_length=2000, null=False, blank=False) category = models.ForeignKey( Category, on_delete=models.CASCADE, default=True, null=False) price = models.DecimalField(max_digits=5, decimal_places=2) description = models.TextField() delivery_time = models.DateTimeField(default=datetime.now, blank=True) is_published = models.BooleanField(default=True) created_at = models.DateTimeField(default=datetime.now, blank=True) digital = models.BooleanField(default=False, null=True, blank=False) def __str__(self): return self.title I want the user to be able to view product, when they select highest, it sorts, when they select lowest it sorts by prices. Have truid different methods … -
Pytesseract - using .traineddata file on hosted server (Heroku)
I have a Vue, Django integrated project. I hosted the Vue project on Netlify and the Django project on Heroku. A python script (integrated into Heroku) is called on certain buttons which extract data and posts this to the Django API to be viewed on the frontend. I have trained a font type for my pytesseract OCR script. However, when i run it on Heroku, it seems like i can only use the 'eng' (normal font) as 'language' for my pytesseract image_to_string function. If I have the .traineddata file of the font type that I want to use, how can I use this file within the pytesseract functions? I can call the individual file, but I need the right TESSDATA_PREFIX as well. Does someone know how to deal with this? Thanks! -
Vue development version works but production doesn't (Vue CLI + Django)
I have build a site using Django and Vue+Vuetify, with Django running the backend and Vue the front end. I have been using Vue CLI to compile by .vue files. However, now that I am preparing to move the code to production version, I have run into following issue: Vue app created by vue-cli-service build does not work. When run in development mode with vue-cli-service build --mode development it all works fine, but the build version doesn't work. The JavaScript console doesn't give any errors. Almost nothing renders and what little renders doesn't seem to have styling included. However, I can see that axios calls do work, and using inspector shows that various elements are added to the body, they simply do not render. However, looking at my package.json I can't see any obvious errors. { "name": "vueapp", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "build-dev": "vue-cli-service build --mode development", "lint": "vue-cli-service lint" }, "dependencies": { "axios": "^0.21.1", "core-js": "^3.6.5", "vue": "^2.6.11", "vue-router": "^3.2.0", "vuetify": "^2.4.0" }, "devDependencies": { "@mdi/font": "^5.9.55", "@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-eslint": "~4.5.0", "@vue/cli-plugin-router": "~4.5.0", "@vue/cli-service": "~4.5.0", "babel-eslint": "^10.1.0", "eslint": "^6.7.2", "eslint-plugin-vue": "^6.2.2", "material-design-icons-iconfont": "^6.1.0", "sass": "~1.32.0", "sass-loader": "^10.0.0", "vue-cli-plugin-vuetify": "~2.4.1", "vue-template-compiler": "^2.6.11", …