django – How can I remove collections after using djongo to embed them in another collection in mongodb?

I am new to Django. I am trying to connect Django with Mongodb with Djongo. But when I use embedded models, Mongodb creates 2 collections for me. How can I remove the embedded collections?

This is my code

class CallHistory(models.Model):
      Time = models.DateField(
      Count = models.IntegerField(default=0)

class History(models.Model):
      SeriNo = models.CharField(max_length=100)
      Call = models.EmbeddedModelField(
        model_container = CallHistory

I don't want to create a CallHistory collection in Mongodb.

django – LDAPError caught while authenticating user: UNWILLING_TO_PERFORM

I am new to LDAP and Django. I am trying to implement LDAP authentication for my Django application, but am having trouble connecting to the LDAP server.
Here is the error code:

Caught LDAPError while authenticating josephsim: UNWILLING_TO_PERFORM({'desc': 'Server is unwilling to perform', 'info': 'Unauthenticated binds are not allowed'})

– Here is my –


logger = logging.getLogger('django_auth_ldap')

AUTH_LDAP_SERVER_URI = "ldap://ldap.m*****"
AUTH_LDAP_BIND_DN = "cn=ldap_user,ou=PEOPLE, dc=m*****, dc=com, dc=my"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=PEOPLE, dc=m*****, dc=com, dc=my", ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")

    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail"

In fact, there was this earlier handover of the CodeIgniter project by former employees with LDAP authentication already implemented, and now I'm trying to re-implement the same authentication system on my Django app. Here are the files:

– application / config / ldap_auth.php

$config('LDAP_SERVER')="ldap.m*****"; //set this the LDAP server

– application / controller / file.php
/ * Login authentication method: LDAP * /

private function _ldap_login() {

$ldap_server = $this->config->item('LDAP_SERVER');
$ldap_port = $this->config->item('LDAP_PORT');
$ldap_suffix = $this->config->item('LDAP_SUFFIX');

$s=@ldap_search($ds, $ldap_suffix, "uid={$this->input->post('userid')}");

if ($s) //LDAP Server Connected
    if ($result('count') != 0)
        if (@ldap_bind($ds,$result(0)('dn'),$this->input->post("password")))

Any help would be appreciated.

Strategy for updating a dashboard in a web app operated by Django

I want to include a dashboard in my Django-based web app to show the current status / results (and the old / archived status / results) for some computing operations in an HPC (Linux) farm.

Tools / workflow

  • The app is created with Django and the data is saved in the Maria DB.
  • I will create the dashboard in Plotly / Dash.
  • I will integrate the dashboard with Django django-plotly-dash Package. However, I will not activate the live update (dashboard) because there are some difficulties configuring / opening ports when deploying the app in a Cloud Foundry service.
  • To forward requests from the server -> HPC, I send a JSON message using the ActiveMQ / STOMP protocol.
  • The HPC starts thousands of jobs (~ 3000) in parallel to process the data. When each job is done, it sends a JSON message back to the app using ActiveMQ / STOMP.
  • This data is then used to update the dashboard and display it to the user.
  • If the user wants to see the status / data for old requests, this data is extracted from the MariaDB for display.


  • I don't have to display the results / status in real time. I can update the dashboard to 30 minutes / 1 hour every 10 minutes (it takes time to process the back-end data). To do this, I just have to save the client information in the DB. Then can the dashboard simply pull out of the DB to present it?

  • Even if you send information from each client -> server, it is better to send lots of small messages or run an aggregator as a daemon that monitors the jobs on the HPC, collects the data / results and then sends a longer message to the Server to upload / save the database (say every time 100 jobs are completed)? The service that provides ActiveMQ has set the default size of each message up to 100 MB.

  • I have often read in the documentation that the size of the message should be kept small, What is small Is it on the order of a few hundred KB per message?

django – most likely due to circular import (How to Solve)

Good night I am new to Django / Python, I am developing a system in which I have a circular relationship, I have the person class and the company in which a person belongs to a company and a company is a person. According to the following classes:

class Pessoa(models.Model):
        (1, ('1. FUNCIONÁRIO')),
        (2, ('2. CLIENTE')),
        (3, ('3. FORNECEDOR')),
        (4, ('4. TRANSPORTADOR')),

        (1, ('1. JURÍDICA')),
        (2, ('2. FISÍCA')),

    nome = models.CharField(

    empresa = models.ForeignKey(

    tipo_cadastro = models.IntegerField(
        ('Tipo Cadastro'),

    tipo_pessoa = models.IntegerField(
        ('Tipo Pessoa'),

class Empresa(models.Model):
    pessoa = models.ForeignKey(

    cnae= models.IntegerField(

    corporacao = models.ForeignKey(

class Corporacao(models.Model):
    nome = models.CharField(

This year I have the following error when doing Makemigrations:

File "D: Develop Projects Python neosis apps core models", line 3, in the file " import Company" D: Develop Projects Python neosis apps core models ", line 5, from .person import Person ImportError: The name & # 39; Person & # 39; from the partially initialized module & # 39; apps.core.models.person & # 39; cannot be imported (most likely due to circular import))

How could you solve that?

Python – Django View tests

I work my way through a Django book and part of it deals with the test cases. In the current chapter I have the following code to start the test cases, but some of them seem to break the DRY principle.

from django.test import TestCase, SimpleTestCase
from django.contrib.auth import get_user_model
from django.urls import reverse

# Create your tests here.
class HomePageTests(SimpleTestCase):
    def test_home_page_status_code(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

    def test_view_url_by_name(self):
        response = self.client.get(reverse('home'))
        self.assertEqual(response.status_code, 200)

    def test_view_uses_correct_template(self):
        response = self.client.get(reverse('home'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'home.html')

I understand the difference between the first and second test case. One tests the path explicitly, the other tests the name that some of my views may use. In the third test, however, it seems to me to be a little superfluous to test the status code of the response object again from the back when we just tested this functionality in the previous test case.

There is a particular advantage if you look up the status code on the back in the third test case.

Since the second and third test cases require exactly the same get response, these methods cannot be taken out and saved in the class themselves, so that they are only executed once or at least set the reverse_path lookup once. Here, too, there is a certain reason or advantage of calling it up each time in the individual test cases.

python – Django authentication with DRF and oauth2

I had a question here, but I managed to clear the bottleneck, but I encountered another problem: I use Django and Django Rest Framework to build an API, and it is used by a front-end application that responds!

Safety has the highest priority. How can I authenticate users with JWT?
I wish it was like Facebook or other systems!
Can I use oauth2.0?

Thank you in advance for your attention!

Problem sorting the query from elasticsearch / django

I have this Django model:

class Profile(User):

rg = models.CharField(max_length=20, null=True,blank=True)
cpf = models.CharField(max_length=15, unique=True, null=True)
about = models.TextField(_('about'),max_length = 10000, null=True, blank=True)
knowledge = models.ManyToManyField(SubCategory, related_name="profile_knowledge")

class Meta:
    verbose_name = _('profile')
    verbose_name_plural = _('profiles')
    db_table = 'pd_profile'
    permissions = (
        ("view_all_users", "Can view user details"),
        ("edit_all_users", "Can edit user details"),
        ("search_profile", "Can search talents"),
        ("user_config", "Can access user config page "),
        ("add_users_permissions", "Can add global permissions to user"),
        ("export_user_data", _("Can export users data")),

def __str__(self):
    return self.full_name

And I would like to query profiles as follows:

query = SearchQuerySet().all().models(Profile)
t = query.filter(content=data.get('value'))
if not t:
    suggestion = query.spelling_suggestion(data.get('value'))
    t = query.filter(content=suggestion)
query = t
query = query.order_by("full_name")

My problem is that it doesn't return in alphabetical order at all. I am doing something wrong? Thank you very much

django-haystack == 2.5.0 djangorestframework == 3.3.2 elasticsearch == 1.5.2

Vulnerability scanner – VeraCode scan of Django View's static code reports "External control of file name or path" with the rendering method

Veracode has reported a security issue related to code that it appears to be fairly harmless. The code consists of Python / Django and the relevant line is:

return render (request, & # 39; core / create-user.html & # 39 ;, context)

The render link for Django is fairly normal and expects a request object, the name of the template, and the context to be passed to the template. I'm not sure why Veracode is complaining about it.

It appears to pick up the word "create-user" from the template name and assume that it is an OS / library method that is called to create a user based on user input. That's why it complains, but that sounds pretty silly to me in the name of Veracode.

Is it really a security issue, if so, why? Or is it false positive?

html – I can't use a Javascript file in a Django project

I am trying to use a javascript file in a Django project. It works correctly in a script tag, but when I try to create a separate file, it doesn't work. I tried to do what is documented in this tutorial. It still doesn't work and the styles come from a CSS code that I've already deleted.

var modal = document.getElementById("myModal");

var btn = document.getElementsByClassName("popup_button")

var span = document.getElementsByClassName("close")(0);

var mVideo = document.getElementById("mVideo");

for (var i = 0; i < btn.length; i++) (function (i) {
  btn(i).onclick = function () { = "block";
    mVideo.src = "".concat(btn(i).id).concat("?autoplay=1");

span.onclick = function () { = "none";
  link = mVideo.src;
  mVideo(i).src = link.substring(0, link.length - 1).concat('0');

window.onclick = function (event) {
  if ( == modal) { = "none";
    link = mVideo.src;
    mVideo.src = link.substring(0, link.length - 1).concat('0');
article#corpo_videos {
    width: 80%;
    margin: 0px auto;
    /* background-color: gray; */
    /* text-align: center; */

.popup_button:hover {
    transform: scale(1.2);
    /* -webkit-transform: scale(1.2); */

.popup_button {
    padding-left: 10px;
    padding-right: 10px;
    border: none;
    outline: none;
    max-width: 23.1%;
    width: auto;
    height: auto;
    margin-bottom: 50px;
    transition: transform 0.5s;

 /* The Modal (background) */
 .modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  /* Modal Content/Box */
  .modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 50%; /* Could be more or less, depending on screen size */
    height: 60%;

  .modal-content iframe {
    display: block;
    margin: auto;
  /* The Close Button */
  .close {
    position: relative;
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    top: -20px;
    left: 10px;
  .close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
{% for id in videos_id %}
{% endfor %}

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

The CSS and Javascript files are in

myProject / myApp / static / css / system.css

myProject / myApp / static / js / modal.js

How do I cut a paginated view in jinja2 django?

I have this paginated generic ListView

class ShoseListView(generic.ListView):
model = Shose
context_object_name = "Shose_list"
template_name = "products/listings.html"
paginate_by = 8

I want to cut it in two and use it, but there is a problem with the slice

     {% for shose in Shose_list|slice(4) %}

Template Syntax Error
Two arguments are required for slice, of which 1 is specified

even though I read the jinja documentation
his job well with an argument