Posts under tag: "Problem"

How to launch python Idle from a virtual environment (virtualenv)

By: summonagus ● at Sept. 2, 2017, 5:29 a.m. ● Posted under: #Tricks, #Problem, #Solution

Question from: Khnle - Kevin I have a package that I installed from a virtual environment. If I just launch the python interpreter, that package can be imported just fine. However, if I launch Idle, that package cannot be imported (since it's only available in one particular virtualenv and not ...

Read More →

Optimizing Django ORM Queries for Best Performance

By: summonagus ● at Aug. 25, 2017, 9:34 p.m. ● Posted under: #Tricks, #Problem, #Database, #Django, #Solution

Django framework already comes with lot of ORM (Object Relational Mapping) functionalities. Once the models are created, you can create, update, retrieve and delete objects using its database abstraction api. Any changes in the models can also be handled using migrations which is pretty awesome. Making queries in django is ...

Read More →

Auto rename file after uploaded

By: summonagus ● at Aug. 5, 2017, 8:24 a.m. ● Posted under: #Tricks, #Problem, #Django, #Solution

Django Auto rename file after uploaded. This method to handle duplicated files in same times. This snippet below is how to do that;import os, time, uuid from django.db import models from django.utils.deconstruct import deconstructible class ImageUploader(models.Model): @deconstructible class PathAndRename(object): def __init__(self, sub_path): self.path = sub_path def __call__(self, instance, filename): # ...

Read More →

Fixed CommandError: Unable to find a locale path to store translations for file

By: summonagus ● at Feb. 27, 2017, 12:04 p.m. ● Posted under: #Problem, #Settings, #Django, #Solution, #Internationalization, #Multi Languages

Hello guys, this day I want to share a simply tutorial how to fix CommandError: Unable to find a locale path to store translations for file <app_name>/ for Django 1.10 In my previous LOCALE_PATHS inside file of is like this: LOCALE_PATHS = ( os.path.join(BASE_DIR, 'projectname/locale'), ) This should an ...

Read More →

Django query to group records with created field

By: summonagus ● at Feb. 9, 2017, 11:53 p.m. ● Posted under: #Problem, #Django, #Solution

Hello guys, this night I want to share a simply tutorial how to querying the objects to group records with created field. This case is what already aksed by someone at stackoverflow.And the question is; in the class Post(models.Model): caption = models.CharField(max_lenght=200) description = models.TextField() created = models.DateTimeField(auto_now_add=True) modified ...

Read More →

Fixed DNS PROBE on Ubuntu

By: summonagus ● at Jan. 22, 2017, 10:32 a.m. ● Posted under: #Problem, #Internet, #Solution

These errors indicate that there is some problem with DNS. check cat /etc/resolv.conf for your DNS settings. And add following name server in /etc/resolv.conf for temporary or in /etc/resolvconf/resolv.conf.d/head for permanent nameserver nameserver To add these two name server address in resolv.conf run command sudo gedit /etc/resolv.conf Copy ...

Read More →

Django: Custom safe excludes from dangerous XSS Injection

By: summonagus ● at Jan. 3, 2017, 7:44 a.m. ● Posted under: #Tricks, #Templates, #Problem, #Django, #Security, #Solution

Django Custom safe excludes from dangerous XSS Injection. Answered from: from bs4 import BeautifulSoup from django import template from django.utils.html import escape register = template.Library() INVALID_TAGS = ['script', 'style'] def clean_html(value): soup = BeautifulSoup(value) for tag in soup.findAll(True): if in INVALID_TAGS: #tag.hidden = True # you also can ...

Read More →

How to custom html choose image upload for django markdownx

By: summonagus ● at Dec. 19, 2016, 9:38 p.m. ● Posted under: #Tricks, #Templates, #Problem, #Django, #Solution, #Ajax

Django markdownx is a Markdown editor built for Django Previously i already created isssue before:, as the owner says: There is no easy way to do it "quick", I think. You could change JS script a bit to be able to send images. This should be a simple ...

Read More →

Understanding @user_passes_test Django

By: summonagus ● at Nov. 28, 2016, 10:05 p.m. ● Posted under: #Tricks, #Problem, #Django, #Security, #Solution

Django decorator has a function to manage the user, once of it is user_passes_test. But, in my implementation i found this problem: ERR_TOO_MANY_REDIRECTS, or 'AnonymousUser' object is not iterable. I need to custom the user by instancing from user models, for example: from django.db import models from django.contrib.auth.models import User ...

Read More →

Step by step how to use multiple databases with database routers in Django

By: summonagus ● at Oct. 26, 2016, 11:29 p.m. ● Posted under: #Tricks, #Problem, #Database, #Settings, #APP, #Django, #Project, #Solution, #SSO, #Multi Databases

1. Please create a new superuser for the second/default/current database. Because you will getting this issue that i already asked before: i use multiple site, multiple env, multiple project, multiple database. and found this error message if use DATABASE_ROUTERS. insert or update on table "django_admin_log" violates foreign key constraint ...

Read More →