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
{% load fieldtype %} | |
{% for field in form.visible_fields %} | |
{% if field|fieldtype == 'CheckboxInput' %} | |
... | |
{% elif field|fieldtype == 'CheckboxSelectMultiple' %} | |
... | |
{% endif %} | |
... | |
{% endfor %} |
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
<table class="table table-bordered"> | |
<thead> | |
<tr> | |
<th>Title</th> | |
<th>Author</th> | |
<th>Date</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for article in articles %} |
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.auth.views import login as auth_login | |
from django.shortcuts import redirect | |
def login(request): | |
if request.user.is_author(): | |
return redirect('/author/') | |
elif request.user.is_reader(): | |
return redirect('/reader/') |
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
TEMPLATES = [ | |
{ | |
'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
'DIRS': [ | |
PROJECT_DIR.child('templates'), | |
], | |
'APP_DIRS': True, | |
'OPTIONS': { | |
'context_processors': [ | |
'django.template.context_processors.debug', |
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
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
from django.contrib.auth.models import User | |
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |
def index(request): | |
# here is the list of elements you want to paginate. | |
user_list = User.objects.all() | |
# `page` is a parameter we will receive from the url, like this: | |
# http://127.0.0.1:8000/users/?page=1 | |
# http://127.0.0.1:8000/users/?page=2 |
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
[ | |
{ | |
"fields":{ | |
"status":"G", | |
"name":"Hacker News", | |
"url":"https://news.ycombinator.com/news", | |
"last_run":"2017-02-22T02:11:16.279Z", | |
"story_url":"https://news.ycombinator.com/item?id=", | |
"slug":"hn" | |
}, |