Skip to content

Instantly share code, notes, and snippets.

View santoshpy's full-sized avatar
🐍
Focusing

Santosh Purbey santoshpy

🐍
Focusing
View GitHub Profile
@santoshpy
santoshpy / urls.py
Last active June 25, 2016 10:09
Django Project Urls.py Patterns Examples In Django, the matching regex group(s) (ie ?P<month>, ?P<id>, ?P<username>) will be passed as a Keyword Argument (**kwarg) to the matching view.
#urls.py
"""
Django 1.9+ Pattern Syntax
"""
from blog.views import (
ArticleView,
YearArchiveView,
MonthArchiveView,
PostSlugView,
@santoshpy
santoshpy / 0_urllib2.py
Created November 25, 2016 14:23 — forked from kennethreitz/0_urllib2.py
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@santoshpy
santoshpy / email_authentication_backends.py
Last active September 28, 2017 05:11
Extends default django ModelBackend for both Email Authentication and Username Authentication against settings.AUTH_USER_MODEL. i.e: user can login with either email or username.
# In any authentication related app create new file email_authentication_backends.py
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend
class EmailAuthBackend(ModelBackend):
"""
Extends default django ModelBackend for both Email Authentication and Username
Authentication against settings.AUTH_USER_MODEL
i.e: user can login with either email or username.
@santoshpy
santoshpy / .gitignore
Last active February 6, 2024 23:52
gitignore file for django project
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
@santoshpy
santoshpy / project_structure.md
Last active September 15, 2023 06:11
# Django Project Directory Structure

Django Project Structure

  • <virtualenv_name>
  • bin
  • include
  • lib
  • src
  • documents
  • requirements >>>>- - base.txt
@santoshpy
santoshpy / django_project_directory_structure.md
Last active March 4, 2020 16:08
Django Project Directory Structure
@santoshpy
santoshpy / email_settings.py
Created October 3, 2017 03:30
Django Email settings
##EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # For development and test only
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # For Production
# Django Eamil Settings for gmail
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '<user>@gmail.com' # use email adress
EMAIL_HOST_PASSWORD = '***********' # use password of your email adress
EMAIL_USE_TLS = True
@santoshpy
santoshpy / interview_sample_questons_1.md
Last active February 3, 2019 08:47
Interview Sample Question

Interview Sample Question

    1. why is not all memory free when Python exits?
    1. write the output of below code:
   var1 = lambda q: q * 5
   var2 = lambda q: q * 3
   x = 2
   x = var1(x)
   x = var1(x)
   x = var2(x)

To start rabbitmq server

sudo rabbitmq-server start

To check status of server

sudo rabbitmqctl status

To stop server

@santoshpy
santoshpy / beautiful_idiomatic_python.md
Last active August 16, 2018 15:37 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]: