This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import transaction | |
@transaction.atomic | |
def create_user_view(request): | |
if request.method == 'POST': | |
user_form = UserCreationForm(request.POST) | |
profile_form = ProfileForm(request.POST) | |
if user_form.is_valid() and profile_form.is_valid(): | |
user = user_form.save() | |
user.refresh_from_db() # This will load the Profile created by the Signal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post"> | |
{% csrf_token %} | |
{{ form }} | |
<button type="submit">Save changes</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load startswith %} | |
<li{% if request.path|startswith:'/settings/' %} class="active"{% endif %}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.conf.urls.static import static | |
urlpatterns = [ | |
# Project url patterns... | |
] | |
if settings.DEBUG: | |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.contrib.flatpages.admin import FlatPageAdmin | |
from django.contrib.flatpages.models import FlatPage | |
from django.utils.translation import ugettext_lazy as _ | |
class CustomFlatPageAdmin(FlatPageAdmin): | |
fieldsets = ( | |
(None, {'fields': ('url', 'title', 'content',)}), | |
(_('Advanced options'), { | |
'classes': ('collapse',), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hmac | |
from hashlib import sha1 | |
from django.conf import settings | |
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseServerError | |
from django.views.decorators.csrf import csrf_exempt | |
from django.views.decorators.http import require_POST | |
from django.utils.encoding import force_bytes | |
import requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.crypto import get_random_string | |
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | |
random_string = get_random_string(50, chars) | |
print(random_string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.contrib.auth.models import User | |
class SignUpForm(forms.ModelForm): | |
username = models.CharField( | |
widget=forms.EmailInput(), | |
label='Email address', | |
required=True, | |
max_length=150 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from apiclient.discovery import build | |
import httplib2 | |
from oauth2client import client | |
from oauth2client import file | |
from oauth2client import tools | |
from web.api.models import Article, PageView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import pathlib | |
import shutil | |
import sys | |
import markdown | |
exclude_dirs = {'_build'} | |
exclude_files = {'README.md'} |
NewerOlder