Django: Redirect HTTP to HTTPS

By: summonagus ● at Oct. 8, 2016, 4:24 a.m. ● Posted under: #Settings, #Django, #Security, #Solution

Django: Redirect HTTP to HTTPS, basically the Django already support to handle this redirection at in your # Redirecting from `HTTP` to `HTTPS` for Django 1.8 or later SECURE_SSL_REDIRECT = True SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') Hope it usefull..

Read More →

Create Command Line interfaces with Python

By: summonagus ● at Oct. 8, 2016, 3:58 a.m. ● Posted under: #Tricks, #Module

Building command line programs has been a long time passion of mine. There’s something magical about making a simple, intuitive, and composable CLI. There’s also nothing more beautiful than chaining together a series of CLI programs to solve a complex problem quickly. Here at Stormpath, we’ve built our entire product ...

Read More →

Quick to understanding git step by step

By: summonagus ● at Oct. 6, 2016, 6:56 a.m. ● Posted under: #Tricks, #Beginner

Quick to understand git step by step. Git is a version control system that is used for software development and other version control tasks. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. Git was created by Linus Torvalds in ...

Read More →

Django Blog Python Learning released v.3.6 with feature autobackup

By: summonagus ● at Oct. 4, 2016, 9:28 a.m. ● Posted under: #Problem, #Database, #APP, #Django, #News, #Project

Previously, the Django already has a method to backup the database to the json file with quick command: $ ./ dumpdata --format=json > outfile.json Yup, with dumpdata. But why this "Django Blog Python Learning" not use it? We need to explore and use another method, so we know what we ...

Read More →

How to make cronjob for Django in Hosting, VPS or Server

By: summonagus ● at Oct. 2, 2016, 5:23 p.m. ● Posted under: #Tricks, #Database, #Django, #Project, #Solution

How to make cronjob for Django in Hosing, VPS or Server. This config also what we do in this site. For example, in your file of /yourproject/yourapp/management/commands/ from import BaseCommand, CommandError class Command(BaseCommand): help = 'To backup your app!' def add_arguments(self, parser): parser.add_argument( 'backup', help='To backup your app!' ) ...

Read More →

Remove all files .pyc with recrusive method

By: summonagus ● at Oct. 2, 2016, 5:15 p.m. ● Posted under: #Tricks, #Solution

Remove all files .pyc with recrusive method - This method simple but important. Example in your project dir is like this: project_dir/ __init__.pyc something.pyc ... core/ __init__.pyc build.pyc Deleting the .pyc files one by one would be spending a lot of time. and you will be ...

Read More →

Change backend gmail to Postmarkapp for Django

By: summonagus ● at Oct. 2, 2016, 5:11 p.m. ● Posted under: #API, #Solution, #Project, #News, #Django, #Module, #Settings

1. Install module of Python Postmark Install this module manually from souce inside your environtment: If you work on Django==1.9.*, requirements only mock.2. Register and Put the Server KeysRegister and put your server API token here: . 101010 is id of your server.Makesure verified your SPF and DKIM. ...

Read More →

Custom redirect urls django

By: summonagus ● at Oct. 2, 2016, 5:06 p.m. ● Posted under: #Tricks, #Django

Example in this problem we need redirect the url http://localhost:8000/a/b/C/123/4/5/ to http://localhost:8000/abC12345 without / slash. 1. In your from django.http import HttpResponse from django.views.generic.base import RedirectView from django.core.urlresolvers import reverse class UserRedirectView(RedirectView): # Ref: permanent = False def get_redirect_url(self, pk): pk = ''.join(str(pk).split('/')) return reverse('pool_fix_page', kwargs={'pk': pk}) def ...

Read More →

E11000 duplicate key error index in mongodb

By: summonagus ● at Oct. 2, 2016, 4:55 p.m. ● Posted under: #Problem, #Database, #Flask, #Solution

E11000 duplicate key error index in mongodb. I found this error after migrating my field from "unique" to "non-unique". And in this problem we use mongoengine for flask. First, i have a model such as bellow class Tag(db.Document): title = db.StringField(max_length=50, unique=True) and then, i need to change it without ...

Read More →

How to minify HTML output in Django

By: summonagus ● at Oct. 2, 2016, 4:40 p.m. ● Posted under: #Tricks, #Templates, #Django

So, you want to compress the size of the HTML that Django generates? Here is the Django way to do it. In order to do this, you'll have to write a middleware for your application. So, create a file called (for this example, but you can name it whatever ...

Read More →