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.decorators import login_required | |
from django.shortcuts import render | |
@login_required | |
def my_protected_view(request): | |
"""A view that can only be accessed by logged-in users""" | |
return render(request, 'protected.html', {'current_user': request.user}) |
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 bands.models import Band, Member | |
class MemberAdmin(admin.ModelAdmin): | |
"""Customize the look of the auto-generated admin for the Member model""" | |
list_display = ('name', 'instrument') | |
list_filter = ('band',) | |
admin.site.register(Band) # Use the default options | |
admin.site.register(Member, MemberAdmin) # Use the customized options |
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 import models | |
group = models.Group.objects.get(name='blogger') | |
users = group.user_set.all() |
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
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.mysql', | |
'NAME': 'DB_NAME', | |
'USER': 'DB_USER', | |
'PASSWORD': 'DB_PASSWORD', | |
'HOST': 'localhost', # Or an IP Address that your DB is hosted on | |
'PORT': '3306', | |
} | |
} |
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
{% if some_bool == None %}{% else %}{% if not some_bool %}False{% endif %}{% 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.utils import simplejson | |
def json_response(something): | |
return HttpResponse(simplejson.dumps(something)) |
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.core.mail import send_mail | |
send_mail('Subject here', 'Here is the message.', 'from@example.com', | |
['to@example.com'], fail_silently=False) |
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.core.mail import send_mail | |
datatuple = ( | |
('Subject', 'Message.', 'from@example.com', ['john@example.com']), | |
('Subject', 'Message.', 'from@example.com', ['jane@example.com']), | |
) | |
send_mass_mail(datatuple) |
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
nuh |
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
Accounts.config(...); |