Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Next element with jQuery
I need to move on to the next element. My code shows 3 different cards and put the option in ddbb, but when click on the option I need to pass the 'screen-view' to the next card when sucess is ok. I tried .next('.card').toggle() and .show() but don't work, any advice? My template: {% for standard in standards %} <div class="card mx-auto mt-4" style="width: 95%;" data-aos="fade-up"> <div class="card-header"> <h5 class="card-title">Estándar {{standard.code}}</h5> </div> <div class="card-body"> <p class="card-text">{{standard.name}}</p> <div class="card-text"> <div class="table-responsive-sm tabla-standard" data-alternative-url="{% url 'answeruser' %}"> <table class="table table-bordered"> <thead class="thead"> <tr> {% for alternative in standard.alternative_set.visible %} <th> <div class="alternative color-{{forloop.counter}} {% if alternative.pk in answeruser_alternative_pks %} btnAlternativeFocus {% endif %}" data-alternative-pk="{{alternative.pk}}"> <button class="btn btnAlternative-{{forloop.counter}}">{{alternative.name}}</button></div> </th> {% endfor %} </tr> </thead> <tbody class="tbody"> <tr> {% for alternative in standard.alternative_set.visible %} <td> <div class="alternativeDetail {% if alternative.pk in answeruser_alternative_pks %} btnAlternativeFocus {% endif %}">{{alternative.detail|safe|linebreaks}}</div> </td> {% endfor %} </tr> </tbody> <tfoot class="tfoot"> <tr> <th colspan="4">{{standard.diagnosis_tools|safe}}</th> </tr> </tfoot> </table> </div> </div> </div> </div> {% endfor %} <script type="text/javascript"> AOS.init({ duration: 1200, }) $(document).on('click', '.alternative', function () { const $this = $(this) const alternative_pk = $this.data('alternative-pk'); console.log(alternative_pk) const url = $('.tabla-standard').data('alternative-url'); $.ajax({ type: "POST", url: url, // dataType: 'json', // contentType: "application/json; charset=utf-8", … -
django authentification login
I created a django project of which it contains 13 templates and I have 4 specific users (manager, consultant, computer scientist) my question is the following how to authorize each user to access his pages during authentication by login? Any idea ? -
Get error The current path, didn’t match any of these
What is wrong with my code yet it seems to me that everything is correct. I am trying to display a test page with this code: -------- urls.py ------- from django.urls import path from . import views urlpatterns = [ path('http_response/', views.search, name='search'), ] --------views.py------- def search(request): return render(request, 'store/search.html') ------------ But I get the error'The current path, didn’t match any of these. ' -
How to set django csrf and session cookies an ionic capacitor app
I am developing an Ionic 6 capacitor app, with a python Django backend. I am trying to set csrf and sessionid cookies to be able to query a backend api. So far everything works well in browser (both desktop and mobile), but does not seem to work in the built app. I am trying to debug the app on the local network, so during this phase the server is running in http mode on LAN. On the frontend, I am using Ionic 6 with capacitor, and I have the following setup: axiosConfig.js import axios from "axios"; const validateStatus = function (status) { return status >= 200 && status < 500; // default }; axios.defaults.xsrfCookieName = "csrftoken"; axios.defaults.xsrfHeaderName = "X-CSRFToken"; axios.defaults.withCredentials = true; axios.defaults.validateStatus = validateStatus; export default axios; The following requests are made from the frontend: requests.js import endpoints from "../../helpers/endpoints"; import axios from "../../helpers/axiosConfig"; export default { async setCSRFToken() { const response = await axios.get(endpoints.csrfToken); // csrf token set here if (response.status === 200) { console.log("CSRF token set"); return true; } else { this.error = response.data.detail; console.log("Error: ", this.error); return false; } }, async login(username, password) { // sessionid is set here const response = await axios.post(endpoints.login, { username, … -
Convert Python UTC Datetime to local timezone before performing django __date filter
I am trying to convert a utc datetime to a local timezone to filter for matching dates. If I passed a date such as 2022-05-26 and want to find all records with a time on that day, a time such as '2022-05-27T22:00:00.000z' would be excluded... even if that time IS on 2022-05-26 in the local timezone. I was previously filtering using queryset = Event.objects.filter(time__date=time) and am trying to do something like: queryset = Event.objects.filter(time.replace(tzinfo=timezone.utc).astimezone(tz=None)__date=time) however that is invalid syntax, but hopefully you get the point... Thanks! -
Static files do not work after connecting Django to AWS
I'm creating an ecommerce site and am trying to deploy by connecting Django to S3 on Amazon Web Services. However, since doing so my static files won't load when I run the server from GitPod, and I get 404 errors for my static files in the terminal (the Django admin page has also lost all its CSS). However, the static files do work on the deployed heroku page. Additionally, I get a 500 server error on heroku when I try to go to my checkout page, but the checkout page does work when I view it via running the server on gitpod. Something has obviously gone wrong with the connection for the static files on AWS, but I can't work out what. It's probably impossible to solve the problem with that info alone, but perhaps someone may be able to help me narrow down the list of possibilities. -
Why I cant POST review form in DJANGO
I don't know whats the problem, I have created Reviews form, i defined everything correct but still all the data do not save in Database after submitting and also I am not getting any kind of error. but as far as i know i have mentioned everything correctly. please correct me, may be i forgot something I am new to python and Django. Reviews Model: class Reviews(models.Model): reviewer_name = models.CharField(max_length=50, unique=True) review = models.TextField() review_date = models.DateField() def __str__(self): return self.reviewer_name Reviews Function in views.py: from home.models import Reviews def reviewForm(request): if request.method == 'POST': review_name = request.users user_review = request.POST.get('user_review') Myreview = Reviews(reviewer_name= review_name, review = user_review, review_date=dt.today()) Myreview.save() messages.success(request, 'Your Review has been submitted') return render(request, "users/user.html") URLS.PY: from home import views urlpatterns = [ path('users/', views.reviewForm, name="review") ] Review Form in HTML: <div class="overlay"> <form method="POST" action="{% url 'review' %}"> {% csrf_token %} <div class="form-group"> <label class="text-white" for="desc">Review</label> <textarea class="form-control" id="user_review" name="user_review" rows="3"></textarea> </div> <button type="submit" class="btn1 btn2 btn-primary">SUBMIT</button> </form> </div> -
Blog matching query does not exist when using slug
i am using slug to show blogs. here's how creating auto slug def Creating_blog(request): form=BlogForm() if User.is_authenticated: if request.method=='POST': form=BlogForm(request.POST,request.FILES) if form.is_valid: blog_obj=form.save(commit=False) blog_obj.author=request.user title=blog_obj.blog_title blog_obj.slug = title.replace(' ','-') + '-'+ str(uuid.uuid4()) blog_obj.save() return redirect('index') return render(request,'blogs/creatingblog.html',context={'form':form}) here's the anchor tag to lead me to the page <a href="{% url 'blog_details' blog.slug|slugify %}">Read More</a> urls.py path('details/<slug:slug>', views.blog_details, name='blog_details'), slug field on models.py slug= models.SlugField(max_length=264,unique=True) But whenever i am trying to visit is shows me DoesNotExist at /details/25-million-likes-b4067224-d5c5-46b1-9ca6-0cba8680cb11 Blog matching query does not exist. i can visit the page when i am using pk of the blog. But here it says query does not exist for slug. -
Django testing environment is missing Group and Permissions: but I created them in a migration
I'm trying to fix a bunch of tests in a codebase, which are failing due to not having permissions (for ex: update ticket). The weird thing is, I have a migration in place which creates auth Groups and adds the appropriate Permissions to the Groups. I feel like I'm missing something fundamental in Django's test environment setup - I thought it applies migrations before running tests, and that migrations are a preferred way over fixtures for something like this where the Group should always 1. exist and 2. have that Permission. The Migration from django.db import migrations from django.core.management.sql import emit_post_migrate_signal def create_groups(apps, schema_editor): # Ensure permissions and content types have been created. db_alias = schema_editor.connection.alias emit_post_migrate_signal(2, False, db_alias) Permission = apps.get_model("auth", "Permission") Group = apps.get_model("auth", "Group") # Create CC group permission = Permission.objects.get( codename="handle_ticket", content_type__model="ticket" ) corps = Group.objects.create(name="CC") corps.permissions.add(permission) def remove_groups(apps, schema_editor): Group = apps.get_model("auth", "Group") cc = Group.objects.filter(name="CC").delete() class Migration(migrations.Migration): dependencies = [ ("my_app", "previous"), ] operations = [ migrations.RunPython(create_groups, remove_groups), ] The test, which fails with an Auth error. def test_update_ticket(self): ticket = factories.TicketFactory(notes="Old notes") cc_group = Group.objects.get(name="CC") assignee = factories.UserFactory() assignee.groups.set([cc_group]) self.client.force_login(assignee) result = self.client.post( reverse("ticket_update", args=[ticket.id]), data={"notes": "New notes"} ) print(assignee.groups.all(), assignee.get_all_permissions(), assignee.has_perm("my_app.handle_ticket")) #### … -
apply multiple python decorators across a code base
What's the pythonic way of applying the same set of decorators across multiple methods in a code base (django tests)? Example: from mock import patch Class A: @patch('module.function.c') @patch('module.function.b') @patch('module.function.a') def test_a1(self): ... @patch('module.function.c') @patch('module.function.b') @patch('module.function.a') def test_a2(self): ... Class B: @patch('module.function.c') @patch('module.function.b') @patch('module.function.a') def test_b1(self): ... -
Django: Serialize a ManyToMany relationship with a through argument via a related OneToOne model
So the subject may or may not be contextually accurate but what I do know is it involves all of the above and I'm hitting a wall... I'm looking to get a Workspace model's owner URL directly on the Workspace something like: Desired Output { "url": "http://127.0.0.1:8000/api/workspaces/1/", "id": 1, "name": "Ws 1", "slug": "ws-1", "users": [ "http://127.0.0.1:8000/api/users/2/", "http://127.0.0.1:8000/api/users/4/" ], "owner": "http://127.0.0.1:8000/api/users/2/" } Models class Workspace(models.Model): name = models.CharField(max_length=80) users = models.ManyToManyField(UserModel, through="workspaces.WorkspaceUser", related_name="workspaces") class WorkspaceUser(models.Mode): user = models.ForeignKey(User, related_name="user_workspaces", on_delete=models.CASCADE) workspace = models.ForeignKey( Workspace, related_name="workspace_users",on_delete=models.CASCADE) class WorkspaceOwner(BaseTimeStampedModel): workspace_user = models.OneToOneField(WorkspaceUser, on_delete=models.CASCADE) workspace = models.OneToOneField(Workspace, related_name="owner", on_delete=models.CASCADE) Serializers class WorkspaceSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Workspace fields = ["url", "id", "name", "slug", "users", "owner"] class WorkspaceUserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = WorkspaceUser fields = ["url", "id", "user"] class WorkspaceOwnerSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = WorkspaceOwner fields = ["url", "id", "user"] How can I best serialize the workspace.owner.workspace_user.user url for the HyperlinkedModelSerializer? Thank you! -
How to get previous saved data while editing profile page in django
while editing my profile page ,i get blank page but i want previous saved data. forms.py class UserEditForm(forms.ModelForm): class Meta: model=User fields=['first_name','last_name','email'] class ProfileEditForm(forms.ModelForm): class Meta: model=Profile fields=['date_of_birth','photo'] views.py @login_required def editprofile(request): user_form=UserEditForm() profile_form=ProfileEditForm() if request.method=='POST': user_form=UserEditForm(data=request.POST,instance=request.user) profile_form=ProfileEditForm(data=request.POST,instance=request.user.profile,files=request.FILES) if user_form.is_valid() and profile_form.is_valid() : user_form.save() profile_form.save() return HttpResponse('profile saved') context={'user_form':user_form,'profile_form':profile_form} return render(request,'socialapp/editprofile.html',context) -
How to send cookie from frontend to backend?
I am using react.js as a frontend and django as backend and I need to send cookie from frontend to backend -
How to Update multiple Images in django?
I was looking for a feature for uploading multiple images and found this solution how to upload multiple images to a blog post in django but that method doesn't provide any explanation about updating those multiple images like image can be removed and added new one. how to update multiple images? -
Django rest framework token in url
How to add a token in url. Like this https://127.0.0.1/api/price?fsym=BTC&tsyms=USD,RUB&api_key=8sfeggasdfwer944bf10b6 -
Django - Not able to get specific data from Model to the View
A bit stuck on getting specific data out from the Model via "POST" to the view. only want the IP to be "POST" back to the view. Here is my function that get post data from the webpage. It gets the data fine but all i want is a single item from the specific row. It is not letting me change the html as I get the following error i change option value in html to " ipofnode.ip_address_field " from "ipofnode.id" " Field 'id' expected a number but got '192.168.1.1'. " If i keep it to "ipofnode.id" , it prints out the entire row on the webpage just fine. I only want the IP to be "POST" back to the view so i can save it as a string and pass it. 1: 192.168.0.216:R1-ISP:VMX def inventory(request): if request.method == "POST": ipnode = Nodes.objects.get(pk=request.POST["ipofnode"]) #savedip = ipnode.ip_address_field.all() listip.append(ipnode) return render(request, "hwinventory/hwinventory.html",{ "allnodesips":Nodes.objects.all()}) hwinventory.html {%extends "home/layout.html"%} {% block body%} <h1 style="text-align:center;">Inventory Check</h1> <form action="{% url 'inventory' %}" method="post"> {% csrf_token %} <select name="ipofnode"> {% for ipofnode in allnodesips %} <option value="{{ ipofnode.id }}">{{ipofnode.hostname}}</option> {% endfor %} </select> <input type="submit"> </form> <a href="{% url 'resultsinventory' %}">View Results</a> {%endblock%} MODEL class Nodes(models.Model): ip_address_field = … -
In Bootstrap 5 why select options doesn't appear in every browsers?
I'm made a page where the user have to choose an options from the dropdown list where other users that matches to a criteria appears. Almost every cases it works well but some users (they are using Chrome or Edge) made a feedback that the options are in the dropdown list but the text has the same color like the background so it is appears just when they hover it like on the image below. In the most of the cases everything works fine and all the names appear. I don't used any any CSS just Bootstrap 5 and Django. <h3 class="mt-4">This is the questions label</h3> <select class="form-select" aria-label="" name="perf01a" id="perf01a"> <option id="opt">nincs</option> {% for u in related_users %} <option>{{ u.user_name.last_name }} {{ u.user_name.first_name }}</option> {% endfor %} </select> <select class="form-select" aria-label="" name="perf01b" id="perf01b"> <option id="opt">nincs</option> {% for u in related_users %} <option>{{ u.user_name.last_name }} {{ u.user_name.first_name }}</option> {% endfor %} </select> <select class="form-select" aria-label="" name="perf01c" id="perf01c"> <option id="opt">nincs</option> {% for u in related_users %} <option>{{ u.user_name.last_name }} {{ u.user_name.first_name }}</option> {% endfor %} </select> What should I do? -
Making a django site that is vulnerable to session hijacking
For a cybersecurity demo, I need to create a website that is vulnerable to session hijacking simply by sniffing a session cookie and integrating it in the attacker's requests' headers. I have tried using many implementations of jwt authentication, and also to simply steal the "sessionid" after having set SESSION_COOKIE_SECURE to "False". I was never able to steal the sessions on my website and would always get redirected to the login page. Can you think of any vulnerable public session cookie mechanism I could implement to steal a session on my django website simply by adding it to my requests' headers ? Thank you very much. -
I am having issues trying to make my first website with django
i just tried to return a Httpresponse but showed me this error: Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 973, in _bootstrap_inner self.run() File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run autoreload.raise_last_exception() File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception raise _exception[1] File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\__init__.py", line 398, in execute autoreload.check_errors(django.setup)() File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\registry.py", line 91, in populate app_config = AppConfig.create(entry) File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\apps\config.py", line 206, in create mod_path, _, cls_name = entry.rpartition(".") AttributeError: module 'asyncio.events' has no attribute 'rpartition' -
How to return rendered html I received from a 3rd party api call in Django?
The frontend requests the /oauth endpoint from our backend. The backend makes a request to a third party, and they return some html to our backend. Is there a django Response method that allows me to return this html, rendered, to the frontend? Something like: url = '3rd/party/url' response = requests.get(url) return Response.render(response.content) I am somewhat new to python/django, so any advice would be lovely. Thank you! -
Django Dynamic Dropdown Menu Not Populating
I'm working on a project where the task is to implement a dynamic drop-down menu where the choices in the menu will change depending on the value that the user selects from a previous drop-down menu. I have the first dropdown menu populated with the values of the name keys in the JSON below (Network 1, Network 2, etc.). My goal is that the second dropdown will populate with a list of the zone values that correspond with the name value that the user selects in the first dropdown. So, if the user selects Network 1 from the first dropdown, the second dropdown will populate with network.1.private.zone as its only option. If the user selects Network 2 from the first dropdown, then the second dropdown will populate with network.2.private.zone as its only option, and so on. Thanks in part to this guide, I've made quite a bit of progress on this. I can see the AJAX request firing in the browser, and the url and networkId values seem to be correct when I console.log them to the browser. But I can't figure out why the dynamic dropdown menu isn't populating. Here is a screenshot of what the page looks like: … -
Django - CKEditor5Field field default font color
I've got 2 CKEditor5Fields in one of my models. I'm running into an issue in the admin panel that when the browser is in dark mode the background color of the field is staying white and the font color is changing to an off-white color making it really hard to read. The text is fine when it's rendered to the page. Is there a way to set the default font color to black so browser mode doesn't matter? Light Mode: Dark Mode : Model properties: property_short_description = CKEditor5Field('property short description', config_name='extends', blank = True, null = True) description = CKEditor5Field('description', config_name='extends') My config: CKEDITOR_5_CONFIGS = { 'default': { 'toolbar': ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ], }, 'extends': { 'blockToolbar': [ 'paragraph', 'heading1', 'heading2', 'heading3', '|', 'bulletedList', 'numberedList', '|', 'blockQuote', 'imageUpload' ], 'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough', 'code','subscript', 'superscript', 'highlight', '|', 'codeBlock', 'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat', 'insertTable',], 'image': { 'toolbar': ['imageTextAlternative', 'imageTitle', '|', 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'], 'styles': [ 'full', 'side', 'alignLeft', 'alignRight', 'alignCenter',] }, 'table': { 'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ], 'tableProperties': { 'borderColors': customColorPalette, 'backgroundColors': … -
By use Django API Function without Django Rest Use, How to call API in dropdown list and display all API fields in dropdown list, below is code wrong
Use this api (url), return type of api List output, API CALL in a select dropdown list please tell me how to call api in dropdown list and display all api fields in dropdown list. <script> $('#mySelectapi').select2({ ajax: { dataType: "json", method: "GET", url: '/auto/multipleselectdjango', processResults: function (data) { // Transforms the top-level key of the response object from 'items' to 'results' return { results: $.map(data, function (payloaddata) { return { text: data.payloaddata, // results: data.payloaddata, // value: payloaddata } }), } } } }); </script> its a Wrong Scripts for call API, it display me all list data in a single row in dropdown Below is my Django function codes: def multipleselectdjango(request): # For check Get Data By url --> auto/autocompdjango/?urldata=a payload = [] # name__icontains=students--> "Use For Search with perform Matching by "icontains", # "name" is model(db) variable Name, students is above declare variable for get url data studentdata = Students_Search.objects.all() for getstudent in studentdata: # "name" is madel(DB) Name payload.append(getstudent.name) return JsonResponse({'status': 200, 'payloaddata': payload}) THIS IS RESULT OF API: MY API return a list Display THIS IS MY FINAL OUTPUT IN HTML PAGE DISPLAY DATA IN SINGLE ROW: MY FINAL OUTPUT HTML PAGE DROPDOWN LIST -
Empty reply from server\n :Running Django on Docker
i recently came across this error on Docker, how can i fix it ? {"Status":"unhealthy", "FailingStreak":56, "Log":[{"Start":"2022-05-27T16:47:50.248335918Z","End":"2022-05-27T16:47:54.375311277Z","ExitCode":52,"Output":" % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0\ncurl: (52) Empty reply from server\n"},{"Start":"2022-05-27T16:47:59.387363405Z","End":"2022-05-27T16:48:03.497278612Z","ExitCode":52,"Output":" % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n\r 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0\r 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 … -
Elasticsearch, what is cause of these failure logs
This is my docker container's logs. What could be the reason of these issues of elastic. It is in my Django project where I have an Advertisement model which I index with elasticsearch and show up them on my page. Some times this container fails and exits what leads to not showing up advertisements on the page. Errors: {"type": "server", "timestamp": "2022-05-27T07:43:46,335Z", "level": "WARN", "component": "r.suppressed", "cluster.name": "docker-cluster", "node.name": "9ddc4968ea4b", "message": "path: /advertisements/_search, params: {index=advertisements}", "cluster.uuid": "Gy7HxyMoRk-oSwqoC6FRWw", "node.id": "L06UoSF_TgGYDDO-APY3Dg" , "stacktrace": ["org.elasticsearch.action.search.SearchPhaseExecutionException: all shards failed", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:663) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:384) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:696) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:467) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.access$000(AbstractSearchAsyncAction.java:62) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:316) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:48) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService$6.handleException(TransportService.java:745) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1290) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1399) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1373) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:50) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.onFailure(SecurityServerTransportInterceptor.java:252) [x-pack-security-7.12.1.jar:7.12.1]", "at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:324) [x-pack-security-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:61) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService.sendLocalRequest(TransportService.java:908) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService.access$100(TransportService.java:68) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService$3.sendRequest(TransportService.java:140) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService.sendRequestInternal(TransportService.java:852) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor.sendWithUser(SecurityServerTransportInterceptor.java:164) [x-pack-security-7.12.1.jar:7.12.1]", "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor.access$300(SecurityServerTransportInterceptor.java:55) [x-pack-security-7.12.1.jar:7.12.1]", "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$1.sendRequest(SecurityServerTransportInterceptor.java:131) [x-pack-security-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:766) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.transport.TransportService.sendChildRequest(TransportService.java:817) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.SearchTransportService.sendCanMatch(SearchTransportService.java:112) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.CanMatchPreFilterSearchPhase.executePhaseOnShard(CanMatchPreFilterSearchPhase.java:81) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.lambda$performPhaseOnShard$3(AbstractSearchAsyncAction.java:300) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.performPhaseOnShard(AbstractSearchAsyncAction.java:337) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.CanMatchPreFilterSearchPhase.performPhaseOnShard(CanMatchPreFilterSearchPhase.java:132) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.run(AbstractSearchAsyncAction.java:226) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.executePhase(AbstractSearchAsyncAction.java:424) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.AbstractSearchAsyncAction.start(AbstractSearchAsyncAction.java:184) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.TransportSearchAction.executeSearch(TransportSearchAction.java:668) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.TransportSearchAction.executeLocalSearch(TransportSearchAction.java:489) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.search.TransportSearchAction.lambda$executeRequest$3(TransportSearchAction.java:283) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:117) [elasticsearch-7.12.1.jar:7.12.1]", "at org.elasticsearch.index.query.Rewriteable.rewriteAndFetch(Rewriteable.java:103) [elasticsearch-7.12.1.jar:7.12.1]", "at …