Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django filter date before deadline
I want to filter the date 5 days before the deadline in Django, I already have a query but not working. How can I solve this? django views def bdeadline(request): def dispatch(self, *args, **kwargs): return super().dispatch(*args, **kwargs) dl = books.objects.filter(deadline = datetime.now().date() +timedelta(days=5)) return render(request, 'deadline.html',{'title':'Car - Deadline', 'dl':'dl'}) -
Could not able to extend user model using OneToOneField because of migrations not changes
I have model named Voter. I want to authenticate it using django authentication. So I added OneToOneField. I am using this tutorial. but when I add bellow line, applyed makemigrations and migrate and try to fetch Voter objects then it generate error user = models.OneToOneField(User, on_delete=models.CASCADE) Previously I thought that i had done something wrong with extending user. But reading other answers in stackoverflow now it seems that it is because of migration is not applying. Code model.py(partial) class Voter(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) # this line map voter with user but it produce error serial_voter_id = models.AutoField(primary_key=True) voter_id = models.CharField(unique=True, max_length=10) voter_name = models.CharField(max_length=255) voter_constituency = models.ForeignKey(Constituency, models.DO_NOTHING, blank=True, null=True) username = models.CharField(unique=True, max_length=32) password = models.TextField() voter_address = models.CharField(max_length=255, blank=True, null=True) area = models.CharField(max_length=10, blank=True, null=True) city = models.CharField(max_length=10, blank=True, null=True) pincode = models.IntegerField(blank=True, null=True) adhar_no = models.BigIntegerField(unique=True) birth_date = models.DateField() age = models.IntegerField() fingerprint = models.TextField(blank=True, null=True) authenticity = models.CharField(max_length=3, blank=True, null=True) wallet_id = models.TextField() class Meta: managed = False db_table = 'voter' migration entry from migrations/0001_initial.py migrations.CreateModel( name='Voter', fields=[ ('serial_voter_id', models.AutoField(primary_key=True, serialize=False)), ('voter_id', models.CharField(max_length=10, unique=True)), ('voter_name', models.CharField(max_length=255)), ('username', models.CharField(max_length=32, unique=True)), ('password', models.TextField()), ('voter_address', models.CharField(blank=True, max_length=255, null=True)), ('area', models.CharField(blank=True, max_length=10, null=True)), ('city', models.CharField(blank=True, max_length=10, null=True)), ('pincode', models.IntegerField(blank=True, … -
Why does my form url pass the same primary key for all posts?
I have an HTML template where I list out posts one by one, and for some reason, Template: {% for post in posts %} ... <form class='bookmark-form' method='POST' action="{% url 'add_bookmark' post.pk %}" data-url='{{ request.build_absolute_uri|safe }}'> {% csrf_token %} <input type="text" value="{{post.pk}}" class="post-pk" hidden> <button type='submit'><img src="/img/bookmark.svg" alt=""></button> </form> ... {% endfor %} Javascript: $('.bookmark-form').submit(function(event){ event.preventDefault() var $formData = $('.post-pk').val() var postData = {csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(), 'post-pk': $formData} var $thisURL = $('.bookmark-form').attr('data-url') || window.location.href var form_action = $('.bookmark-form').attr('action') console.log($formData) $.ajax({ method: "POST", url: form_action, data: postData, success: function (data) {console.log(data)}, error: function(data) {console.log("Something went wrong!");} }) return false; }) Views.py Add Bookmark Function def add_bookmark(request, pk): if request.method=='POST' and request.is_ajax(): post = Post.objects.get(pk=pk) print(pk) user = request.user user.bookmarks.add(post) user.save() print(user.bookmarks.all()) return JsonResponse({'result': 'ok'}) else: return JsonResponse({'result': 'nok'}) HTML Rendered Page: Regardless of which bookmark button I click on, I always get the same output in my terminal and console log. Terminal: 10 <QuerySet [<Post: Hogwarts, a History>, <Post: The Truth: My Parents are Dentists>, <Post: How to Organize Money: An Easy 10000 Steps>, <Post: Reallllllllly Old Post>, <Post: My First Serious Post>]> Console Log: 10 {'result': "ok"} where 10 is the primary key for the 'My First Serious Post' Post. I can't … -
How do I display the question field in the page where I have used Answers List View in Django?
I am creating a Questions Answers website like Quora using Django. I have created a ListView for questions on the home page and by clicking on a particular question I can see the question and all the answers to that question just like Quora. So for that I have created two models below: class Questions(models.Model): questions_asked = models.CharField(default='' , max_length = 250) date_asked=models.DateTimeField(default=timezone.now) author = models.ForeignKey(Profile , on_delete = models.CASCADE) #Profile is also a model I created but not putting it here as it is not necessary. It #has fields User,description,followers,image def get_absolute_url(self): return reverse('test Home') def __str__(self): if self.questions_asked[-1]!='?': return f'{self.questions_asked}?' else: return f'{self.questions_asked}' class Answers(models.Model): answer = models.CharField(default='No Answers yet' , max_length = 1000) date_answered = models.DateTimeField(default=timezone.now) question_answered = models.ForeignKey(Questions , on_delete = models.CASCADE) author = models.ForeignKey(Profile , on_delete = models.CASCADE) def get_absolute_url(self): return reverse('test quest detail' , kwargs={'pk':self.question_answered.pk}) def __str__(self): return f'{self.answer}' When a question is clicked I pass its primary key to the next url which displays the Answers. When the answers database has some answers I can print the question in tag on the HTML template as shown. This is the HTML template where I want to show the question clicked and the list of … -
Unable to define a ForeignKey field in Django models
I am not able to define ForeignKey relation from UsersGroups model with the other two models Roles and Users. It throws an error - Exception in thread django-main-thread: Traceback (most recent call last): File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/db/models/fields/related.py", line 786, in __init__ to._meta.model_name AttributeError: type object 'Roles' has no attribute '_meta' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run autoreload.raise_last_exception() File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception raise _exception[1] File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute autoreload.check_errors(django.setup)() File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/Users/jeetpatel/Desktop/env/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/jeetpatel/Desktop/eitan-app/users_and_auth/models.py", line 31, in <module> class UsersGroups(): File "/Users/jeetpatel/Desktop/eitan-app/users_and_auth/models.py", … -
Not all HTML form inputs save from a previous page
I am making an e-commerce website where a user can post an order. Posting the order is done with a simple HTML form. After the user posts an order, they are sent to a confirmation page, where they have the option of going back to the order form to edit their order (this button is equivalent to the back button on a browser). All of the fields, except for the first two, are saved and already put into the form, and I cannot figure out why. I want all of the fields to be cached, and already put into the form when the user goes back. I have been googlig this for hours, but everyone seems to want to do the opposite of me :( If it helps, I'm using the django web-framework. Fields that don't save: <div class="row justify-content-center mt-3"> <div class="col-md-4"> <h5>Pick Up Address</h5> <input class="form-control" id="autocomplete" name = "pu_addy" onFocus="geolocate()" type="text" size = '40' required/> <div class = "invalid-feedback"> Please Choose a Pickup Address </div> </div> <div class="col-md-4"> <h5>Delivery Address</h5> <input class="form-control" id="autocomplete2" name = "del_addy" onFocus="geolocate()" type="text" size = '40' required/> <div class = "invalid-feedback"> Please Choose a Delivery Address </div> </div> </div> ex of field … -
Django Pytz timezone full names with GMT value
pytz provides a list of timezones in formats like America/Chicago, America/Los_Angeles, Asia/Kolkata or the tz abbreviation. I want the full name for timezones GMT value like the following (GMT-11:00) Pacific/Pago_Pago (GMT-07:00) America/Santa_Isabel -
Why I am getting the NoReverseMatch error and how can I solve it?
When It executes it show me a error like this "reverse for 'book' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P[0-9]+)/book$'] Views <form action="{% url 'book' flight.id %}" method="post"> Urls path('', views.index, name='index'), path('<int:flight_id>', views.flight, name='flight'), path('<int:flight_id>/book', views.book, name='book') Error NoReverseMatch at /1 Reverse for 'book' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P[0-9]+)/book$'] ` -
TemplateDoesNotExist at / tasks/list.html
I am following a tutorial on how to build a To Do App and for some reason It should change the title on the page to To Do as an <\h3> but its giving me an TemplateDoesNotExist at / tasks/list.html when I change it to return render(request, 'tasks/list.html'). I created a template folder and put my list.html on there, but the part of 'tasks/list.html' is highlighted so something is wrong with that file. -
ProgrammingError at /cart/address/ column order_useraddress.type does not exist
I am trying to create an eCommerce application. And for useraddress (Billing and shipping ) want something like below. Here have a model called Order and UserAddress , which is class Order(models.Model): cart = models.ForeignKey(Cart,on_delete=models.CASCADE) user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE) start_date = models.DateTimeField(auto_now_add=True) ordered_date = models.DateTimeField() ordered_total = models.PositiveIntegerField() shipping_price = models.PositiveIntegerField(default=0) ordered = models.BooleanField(default=False) billing_address = models.ForeignKey(UserAddress,related_name='billing_address',on_delete=models.CASCADE) shipping_address = models.ForeignKey(UserAddress,related_name='shipping_address',on_delete=models.CASCADE,default=None) and class UserAddress(models.Model): BILLING = 'billing' SHIPPING = 'shipping' ADDRESS_TYPE = ( (BILLING , 'Billing'), (SHIPPING, 'Shipping') ) user = models.ForeignKey(UserCheckout, on_delete=models.CASCADE) name = models.CharField(max_length=50) phone = models.CharField(max_length=21,null=True) street_address = models.CharField(max_length=50) home_address = models.CharField(max_length=50) type = models.CharField(max_length=100,choices=ADDRESS_TYPE) def __str__(self): return self.user def get_full_address(self): return '{0}, {1},{2}'.format(self.name ,self.user,self.phone ) And my View is class AddressFormView(FormView): form_class = AddressForm template_name = 'orders/address_select.html' def dispatch(self, request, *args, **kwargs): b_address, s_address = self.get_address() if not (b_address.exists() and s_address.exists()): messages.success(self.request, 'Please add an address before continuing') return redirect('add_address') # redirect before checkout return super(AddressFormView, self).dispatch(request, *args, **kwargs) def get_address(self, *args, **kwargs): user_checkout = self.request.session['user_checkout_id'] b_address = UserAddress.objects.filter( type=UserAddress.BILLING, user_id=user_checkout) s_address = UserAddress.objects.filter( type=UserAddress.SHIPPING, user_id=user_checkout) return b_address, s_address def get_form(self): form = super(AddressFormView, self).get_form() b_address, s_address = self.get_address() form.fields['billing_address'].queryset = b_address form.fields['shipping_address'].queryset = s_address return form def form_valid(self, form, *args, **kwargs): billing_address = form.cleaned_data['billing_address'] shipping_address = form.cleaned_data['shipping_address'] … -
How do you use Ajax with Django to submit a form without redirecting/refreshing, while also calling the views.py function?
I would like to create a system for bookmarking posts, where there would be a page of posts to scroll down, and if you like one in particular, you can click on a button to save it to your bookmarks. I've searched the entire day for a solution that allows me to save the post to the User's Bookmarks, while also not refreshing/redirecting, but I have only managed to find methods that solve one problem at a time, not both. I'm not interested in changing the template view itself, but rather just saving the data into the database. My Template Code: <form class='bookmark-form' method='POST' action="{% url 'add_bookmark' %}" data-url='{{ request.build_absolute_uri|safe }}'> {% csrf_token %} <input type="text" value="{{post.pk}}" name="post-pk" hidden> <button type='submit'><img src="/img/bookmark.svg" alt=""></button> </form> My Ajax Code: $('.bookmark-form').submit(function(event){ event.preventDefault() var postData = {csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),} var $formData = $(this).serialize() var $thisURL = $('.bookmark-form').attr('data-url') || window.location.href $.ajax({ method: "POST", url: $thisURL, data: postData, success: function (data) {console.log(data)}, error: function(data) {console.log("Something went wrong!");} }) return false; }) My Views.py Function to save the bookmark: def add_bookmark(request): if request.method=='POST': pk = request.POST.get('post-pk') post = Post.objects.get(pk=pk) user = request.user user.bookmarks.add(post) user.save() print(user.bookmarks.all()) return JsonResponse({'result': 'ok'}) else: return JsonResponse({'result': 'nok'}) The current result is that the page … -
Django Diplay Data leafleft
I am learning djnago , I would like to display an html page (in template forlder) into another html file by keeping {% extends 'base.html' %} which my template HTML that has my nav bar, CSS , javascritp.. the structure: App1=>templates=>App1=>map.html (is a map app html file) App1=>templates=>App1=>home.html Src=>templates=>base.html in home.html I would like to diplay map.html and all base.html elements (nav bar, CSS, javasript) Here is my base .html code : <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- semantic UI --> <!--Chart js--> <!-- jQuery --> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <title>skill-site | {% block title %} {% endblock title %}</title> </head> <body> {% include 'navbar.html' %} {% block scripts %} {% endblock scripts %} <div class="container ui"> {% block content %} {% endblock content %} </div> </body> </html> here is the code for home.html but it is not working: {% extends 'base.html' %} {% block title %}my map{% endblock title %} {% block content %} {% include './map.html' %} {% endblock content %} Thanks for your help -
Dango.urls.exceptions.NoReverseMatch: Reverse for 'app_list' with keyword arguments '{'app_label': ''}' not found. 1 pattern(s) tried
I am trying to send certain parameters from my views to a custom changelist.html, but I keep getting the error : django.urls.exceptions.NoReverseMatch: Reverse for 'app_list' with keyword arguments '{'app_label': ''}' not found. 1 pattern(s) tried I know the root cause of this is I cannot find all the variables needed to be passed by the changelist_view() which is why it is failing. I am not sure how to get this object cl : cl.opts|admin_urlname -
Django background task runner on server?
I'm trying to run a background task runner on the Django web server. I'm not that familiar with Django but I've done this with asp.net before. So essentially I have the html and JS send a post, which will be a file, usually a huge file, then Django will send back a hash for which to check the status of the file upload. The website will then have a processing bar that tells the user what percent is uploaded or if it has crashed. Is there a way to do this in Django? In C# there's things called delegates for this, where you can just check the status of the job, but the web server still receives requests, cause I want to site to keep pinging the server to get the status. -
How do I transfer test database to product database
I'm working on an Django project, and building and testing with a database on GCP. Its full of test data and kind of a mess. Now I want to release the app with a new and fresh another database. How do I migrate to the new database? with all those migrations/ folder? I don't want to delete the folder cause the development might continue. Data do not need to be preserved. It's test data only. Django version is 2.2; Python 3.7 Thank you. -
Django- insert image in password-reset email
I am implementing Django inbuilt functionality of the password reset. I have overridden the standard email template but I don't know how to include an image in that email template. I have tried the static thing but its giving me a plain text in the email. password_reset_email.html {% load static %} {% load i18n %}{% autoescape off %} {% blocktrans %}Hey, You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} {% trans "Please go to the following page and choose a new password:" %} {% block reset_link %} {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} {% endblock %} {% trans "Your username, in case you've forgotten:" %} {{ user.get_username }} {% trans "Thanks for using our site!" %} {% blocktrans %}The {{ site_name }} team{% endblocktrans %} {% <img src="{% static 'img/IMG_2095.jpg' %}" alt="My image"> {% endautoescape %} Email which i received -
Most efficient way to query Django model by distinct groups and iterate over those subset queries
I am trying to iterate over all of the fields in my model by grouping them by the date_created field and iterating over each query. I have been able to do so but my method seems inefficient. Is there a better, cleaner way? data = model.objects.all() distinct_dates = data.values('date_created').distinct() for each_date in distinct_dates: data.filter(date_created=each_date['date_created']) The values of each_date would be each unique date associated with the model and that field -
Are forms necessary for Django authentication?
I'm new to Django and I'm working on a project which will be using APIs with Django REST framework. And working on it, creating the authentication using DjangoDoc AUTH, I was wondering if it was necessary to use these forms, are there any other authentication or validation methods? I took a look at these articles: DjangoDoc Quora Django Tutorial But I can't see if they're really necessary or if there is another way. Thanks for your responses! -
How to concatenate list of query sets in django models
I have list of query sets and need to connect them into one. How to concatenate list of query sets into one? class TagListAPIView(generics.ListAPIView): serializer_class = serializers.TagSerializer def get_queryset(self): search_words = self.request.query_params['search_with'].split() querysets = [] for word in search_words: queryset = Tag.objects.filter( Q(name__contains = word) ) querysets.append(queryset) return querysets # ListAPIView does not accept this -
Multiple Files In Email Django
I have a list of files, each with its own checkbox. I then get a list of all of the items where the checkbox is marked. I would like for these files to be passed to my view and to be automatically attached. Here is the view which shows the list of files: def DocListView(request, pk): if request.method == "POST": documents = request.POST.getlist('checks') else: return render(request, 'doc_list.html', context) doc_list.html <div> <ul class="list-group"> {% for item in PackingListDocs %} <li class="list-group-item"> <a href="{% url 'EditPackingListView' item.Packing_List.pk %}" class="a" type="button"> <div class="md-v-line"></div><input type="checkbox" name="checks" value="{{ item.PackingListDocument.url|default_if_none:'#' }}">{{item.Packing_List.Name}}<a class="doclink" href="{{ item.PackingListDocument.url|default_if_none:'#' }}" download>View Doc</a> </a> </li> {% endfor %} </ul> </div> So as you can see I get a list ```documents = request.POST.getlist('checks'). Now my next view currently looks like this. def email(request): if request.method == "POST": form = EmailForm(request.POST,request.FILES) if form.is_valid(): post = form.save(commit=False) # post.published_date = timezone.now() post.save() email = request.POST.get('email') subject = request.POST.get('subject') message = request.POST.get('message') document = request.FILES.get('document') email_from = settings.EMAIL_HOST_USER recipient_list = [email] email = EmailMessage(subject,message,email_from,recipient_list) base_dir = 'media' email.attach_file('Poseidon/media/media/'+str(document)) email.send() return redirect('HomeView') else: form = EmailForm() return render(request, 'docemail.html', {'form': form}) It works fine, but it makes the user choose a file to upload, and I can … -
Django submit button not working on Ajax request
I am building a website which users can create posts and comment on it, however, after clicking the submit button in the post_detail.html template to submit the comment, nothing happens and I cannot een see an error. I am using jQuery to submit the form this is my post_detail view: @login_required def post_detail(request, id): data = dict() post = get_object_or_404(Post, id=id) if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(False) comment.post = post comment.name = request.user comment.save() comments = post.comments.all() data['form_is_valid'] = True data['comments'] = render_to_string('home/posts/post_detail.html', { 'comments':comments }, request=request) else: data['form_is_valid'] = False else: form = CommentForm comments = post.comments.all() context = { 'form': form, 'comments': comments, 'post': post } data['html_data'] = render_to_string('home/posts/post_detail.html', context,request=request) return JsonResponse(data) this is my post_detail.html template: {% load crispy_forms_tags %} {% load static %} <script src="{% static 'js/comment.js' %}"></script> <div class="modal-header-sm"> <button type="button" class="close mx-2" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="card mt-3 rounded-0 mb-3" style="max-width: 100rem !important;"> <div class="card-body text-dark"> <div class="d-flex"> <img class="img-create-post rounded-circle mr-2" style="width: 50px;height: 50px;" src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg" alt="Profile image"> <span class="align-text-top"><a class="mr-2 text-dark font-weight-bolder" href="#">{{ post.author.first_name }} {{ post.author.last_name }} </a><br><p class="font-weight-light text-muted">{{ post.title }}</p></span> <div class="float-right text-right ml-auto"> <p class="text-muted small" style="font-size: 0.7rem;">{{ post.date_posted|date:"F d, … -
Subtracting from a IntegerField field in django
I am a medical technologist trying to build a inventory program for my laboratory. My goal is to have a table that shows all of the reagent we have in a particular section of the lab and then display it to the user. I have been able to accomplish this by using django-tables2. What I would like to do next is have a form that allows the user to select the reagent they take out, then the quantity of which they took out, submit the form and then have whatever quantity they took be subtracted from the total reagent count of that particular reagent. Here is what I have so far. Any help is appreciated! forms.py from django import forms class ReagentCheckoutForm(forms.ModelForm): reagent_name= forms.CharField() amount_taken= forms.IntegerField() models.py class Inventory(models.Model): reagent_name= models.CharField(max_length=30) reagent_quantity= models.IntegerField() views.py def reagent_checkout(request): if request.method == 'POST': form= ReagentCheckoutForm(request.POST) if form.is_valid(): form.save() reagent_name= form.cleaned_data['reagent_name'] amount_taken= form.cleaned_data['amount_taken'] -
Django 1.11 to 2.2 with jQuery
I have working application in Django 1.11. It has a few forms and filters that use jQuery, bootstrap, select2, all included in a scripts block in a base.html file. When I upgrade to Django 2.2, one of the forms stops working with a "Uncaught TypeError: $(...).select2 is not a function" error in the (browser) console. Moving jQuery, bootstrap, and select2 from the to the in base.html resolves this, but causes a different form to stop working with a "Uncaught TypeError: $(...).select2 is not a function" error in the (browser) console. Where should I be looking to debug this issue? What could have changed from 1.11 to 2.2 to cause the first error? -
Getting errorTemplate DoesNotExist while adding new page using new class (wagtail, django)
The problem is that when creating a page using the new class, I get a TemplateDoesNotExist error. Full error text: TemplateDoesNotExist at /green-tea/ home/product.html Request Method: GET Request URL: http://relizerel.pythonanywhere.com/green-tea/ Django Version: 3.0.4 Exception Type: TemplateDoesNotExist Exception Value: home/product.html Exception Location: /home/relizerel/.virtualenvs/env/lib/python3.8/site-packages/django/template/loader.py in get_template, line 19 Python Executable: /usr/local/bin/uwsgi Python Version: 3.8.0 Python Path: ['/home/relizerel/myshopwt', '/var/www', '.', '', '/var/www', '/home/relizerel/.virtualenvs/env/lib/python38.zip', '/home/relizerel/.virtualenvs/env/lib/python3.8', '/home/relizerel/.virtualenvs/env/lib/python3.8/lib-dynload', '/usr/lib/python3.8', '/home/relizerel/.virtualenvs/env/lib/python3.8/site-packages'] Server time: Вт, 31 Мар 2020 02:25:43 +0200 My model.py file: from django.db import models from modelcluster.fields import ParentalKey from wagtail.core.models import Page, Orderable from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.contrib.settings.models import BaseSetting, register_setting class HomePage(Page): pass class Product(Page): sku = models.CharField(max_length=255) short_description = models.TextField(blank=True, null=True) price = models.DecimalField(decimal_places=2, max_digits=10) image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) content_panels = Page.content_panels + [ FieldPanel('sku'), FieldPanel('price'), ImageChooserPanel('image'), FieldPanel('short_description'), InlinePanel('custom_fields', label='Custom fields'), ] class ProductCustomField(Orderable): product = ParentalKey(Product, on_delete=models.CASCADE, related_name='custom_fields') name = models.CharField(max_length=255) options = models.CharField(max_length=500, null=True, blank=True) panels = [ FieldPanel('name'), FieldPanel('options'), ] @register_setting class MushkinoSettings(BaseSetting): api_key = models.CharField( max_length=255, help_text='Ваш публичный ключ API Мушкино' ) My base.py (settings.py) file: import os PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # Application … -
I have error message " for file changes with StatReloader Exception in thread django-main-thread:"
I have errors in configuration, and when I had been downloading the project from Github that error shown to me when I run the server that problem happened also I tried to create a new project, so the project run. How can I avoid this problem and solve it? Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\config.py", line 90, in create module = import_module(entry) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\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 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'mediumeditor' Traceback (most recent call last): File "C:/xampp/htdocs/athar/manage.py", line 21, in <module> main() File "C:/xampp/htdocs/athar/manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute super().execute(*args, **options) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 369, in execute output = self.handle(*args, **options) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle self.run(**options) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run autoreload.run_with_reloader(self.inner_run, **options) File "C:\Users\promi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 599, in run_with_reloader start_django(reloader, main_func, *args, **kwargs) …