SlideShare a Scribd company logo
Django Reference Sheet
                                                                                                          Django Admin SQL Commands
                                Project Setup
                                                                                               All the following commands output sql specific to the
Create A Project's Directory Structure
                                                                                               appname specified in the command and should be
django-admin.py startproject projectname
                                                                                               run from with the projectname directory.
(this command needs to be issued in the directory you w ant the project to be in)

                                                                                               django-admin.py sqlinitialdata appname
Customize the DB and other setting in the
                                                                                               Outputs the initial-data inserts required for Django's
projectname/settings/main.py file
                                                                                               admin framework.
Initialize the DB
                                                                                               django-admin.py sql appname
django-admin.py init
                                                                                               Outputs the table creation statements
(this command should be issued in your projectname directory)

Set your DJANGO_SETTING_MODULE environment variable                                            django-admin.py sqlall appname
Unix:                                                                                          Outputs both the sqlinitialdata and sql data
export DJANGO_SETTINGS_MODULE=projectname.settings.main
Windows:                                                                                       django-admin.py sqlindexes appname
set DJANGO_SETTINGS_MODULE=myproject.settings.main                                             Outputs the the create index statements
(you'll probably w ant to set these permanently in your ~/.bashrc file in Unix or your my
computer properties in Window s)
                                                                                               django-admin.py sqlclear appname
                                                                                               Outputs the the drop table statements and the
More Details: http://www.djangoproject.com/documentation/tutorial1/
                                                                                               delete statements for deleting the “initialdata”.
                                 App Setup
Create an App's Directory Structure                                                            django-admin.py startapp appname
django-admin.py startapp appname                                                               (this should be issued in your projectname/apps directory)
(this command should be issued in your projectname/apps directory)
                                                                                               More Details:
Setup App's models in the projectname/apps/appname/models/appname.py                           http://www.djangoproject.com/documentation/
file                                                                                           tutorial1/#activating-models
                                                                                                                 Template Syntax
Add the App to the INSTALLED_APPS in projectname/settings/main.py
                                                                                               There are two types of syntax:
                                                                                               {% something %} - For tags which include blocks
Install the App in the DB
                                                                                               and functional items like loops, if statements, and
django-admin.py install appname
                                                                                               includes.
(this command should be issued in your projectname directory)

                                                                                               {{ variable }} - For variable insertion where
More Details:
                                                                                               “variable” is replaced with it's value.
http://www.djangoproject.com/documentation/tutorial1/#creating-models
                                              URL Dispatcher Sample Config Files
Sample projectname/settings/urls/main.py file
from django.conf.urls.defaults import *
urlpatterns = patterns('',
    (r'^weblog/',                include('django_website.apps.blog.urls.blog')),
    (r'^documentation/', include('django_website.apps.docs.urls.docs')),
    (r'^comments/',              include('django.contrib.comments.urls.comments')),
    (r'',                        include('django.conf.urls.flatfiles')),
)

Sample projectname/apps/blog/urls/main.py file
from django.conf.urls.defaults import *
info_dict = {
    'app_label': 'blog',
    'module_name': 'entries',
}
urlpatterns = patterns('django.views.generic.date_based.',
   (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$', 'archive_day', info_dict),
   (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict),
   (r'^(?P<year>d{4})/$', 'archive_year', info_dict),
   (r'^/?$', 'archive_index', info_dict),
)


                 Italicized Text – Placeholder names for your object(s)                •    Courier Text – Commands you type in
Template Filters
add - Adds the arg to the value                                              random - Returns a random item from the list
addslashes - Adds slashes, for passing strings to JavaScript.                removetags - Removes a space separated list of [X]HTML
Capfirst - Capitalizes the first character of the value                      tags from the output
center - Centers the value in a field of a given width                       rjust - Right-aligns the value in a field of a given width,
cut - Removes all values of arg from the given string                        Argument: field size
date - Formats a dateto the given format using “now” format                  slice - Returns a slice of the list.
default - If value is unavailable, use given default                         slugify - Converts to lowercase, removes non-alpha chars
dictsort - Takes a list of dicts, returns that list sorted by the            and converts spaces to hyphens
property given in the argument.                                              stringformat - Formats the variable according to the
dictsortreversed - Takes a list of dicts, returns that list sorted in        argument, a string formatting specifier. This specifier uses
reverse order by the property given in the argument.                         Python string formating syntax, with the exception that the
divisibleby - Returns true if the value is divisible by the argument         leading quot;%quot; is dropped.
escape - Escapes a string's HTML                                             striptags - Strips all [X]HTML tags
filesizeformat - Format the value like a 'human-readable' file.              time - Formats a time according to the given format (same
First - Returns the first item in a list                                     as the now tag).
fix_ampersands - Replaces ampersands with &amp; entities                     timesince - Formats a date as the time since that date
floatformat - Displays a floating point number as 34.2 (with one             (i.e. quot;4 days, 6 hoursquot;)
decimal places) - but only if there is a decimal point.                      title - Converts a string into titlecase
get_digit - Given a whole number, returns the requested digit of it,         truncatewords - Truncates a string after a certain number
where 1 is the right-most digit, 2 is the second-right-most digit, etc.      of words. Argument: Number of words to truncate after.
Returns the original value for invalid input,                                unordered_list - Recursively takes a self-nested list and
join - Joins a list with a string, like Python's str.join(list)              returns an HTML unordered list -- WITHOUT opening and
length - Returns the length of the value - useful for lists                  closing <ul> tags.
length_is - Returns a boolean of whether the value's length is the           upper - Converts a string into all uppercase
argument                                                                     urlencode - Escapes a value for use in a URL
linebreaks - Converts newlines into <p> and <br />s                          urlize - Converts URLs in plain text into clickable links
linebreaksbr - Converts newlines into <br />s                                urlizetrunc - Converts URLs into clickable links, truncating
linenumbers - Displays text with line numbers                                URLs to the given character limit. Argument: Length to
ljust - Left-aligns the value in a field of a given width, Argument:         truncate URLs to.
field size                                                                   wordcount - Returns the number of words
lower - Converts a string into all lowercase                                 wordwrap - Wraps words at specified line length.
make_list - Returns the value turned into a list.                            Argument: number of words to wrap the text at.
phone2numeric - Takes a phone number and converts it in to its               yesno - Given a string mapping values for true, false and
numerical equivalent                                                         (optionally) None, returns one of those strings according to
pluralize - Returns 's' if the value is not 1.                               the value. Sample argument quot;yeah,no,maybequot; returns yeah
pprint - A wrapper around pprint.pprint -- for debugging.                    for true, no for false, and maybe for none.
                                                         Template Tag Reference
block – Defines an area that the content can be inserted into.          if – Evaluates for true or false
{% block content %}Default Content{% endblock %}                        {% if athlete %}{{ athlete }}{% endif %}
comment - {% comment %}{% endcomment %}                                 (if statements can have “not” and “or”, but are not allow ed to have “and”)
cycle – Rotates through items                                           ifchanged – Outputs it's content if different from last loop.
<tr class=quot;{% cycle red,blue as colors %}quot;>..</tr> {% ifchanged %}{{ name }}{% endifchanged %}
<tr class=quot;{% cycle colors %}quot;>...</tr>                                 (code w ould be w ithin for loop)
                                                                        ifnotequal – Checks for equality
debug – Outputs a bunch of debug info {% debug %}
                                                                        {% ifnotequal v1 v2 %}hi{% endifnotequal %}
extends – Inherits from another template
                                                                        load – loads a custom tag set {% load comments %}
{% extends quot;basequot; %}
                                                                        now – Outputs current date {% now quot;jS F Y H:iquot; %}
(leave off the .html for the template name)
filter – Applies the specified filter(s) to the content in between      (formatting matches php's date function for the most part)
{% filter lower %}Lowercase this{% endfilter %}                         regroup –Regroup a list of like objects by an attribute
firstOf – Outputs the first true variable, or nothing if all are false. {% regroup people by gender as grouped %}
{% firstof var1 var2 var3 %}                                            ssi – Includes a file
for – Loop through list item                                            {% ssi /home/html/side.html parsed %}
{% for athlete in athlete_list %}                                       (if the option passed “parsed it w ill be treated as a template)
                                                                        templatetag – Used to escape template tags
       {{ athlete.name }}
                                                                        {% templatetag openblock %}
{% endfor %}
                                                                              (arguments open/closeblock and open/closevariable)
forloop.counter = current loop iteration starting at 1
                                                                              widthratio – Calculates the ratio of a given value to a
forloop.counter0 = current loop iteration starting at 0
forloop.first = True if first time through loop                               maximum value, and then applies that ratio to a constant.
forloop.last = True if this is the list time through the loop                 {% widthratio this_value max_value 100 %}
forloop.parentloop = Parentloop counter (???)


                  Italicized Text – Placeholder names for your object(s)       •   Courier Text – Commands you type in
Sample Template
{% extends quot;basequot; %}
{% block title %}{{ title|title }}{% endblock %}
{% block intro %}
      Default Intro Copy that can be replaced by templates extending this one
{% endblock %}
{% block content %}
   {% for entry in blog_entries %}
      {% ifchanged %}<h1>{{ entry.pub_date|date”F, y” }}</h1>{% endifchanged %}
      <h2>{{ entry.title }}</h2> <p>
      {{ entry.body|escape|urlizetrunc:quot;40quot;|linebreaks}}</p>
   {% endfor %}

{% endblock %}

Additional Template Resources:
http://www.djangoproject.com/documentation/templates/
http://www.djangoproject.com/documentation/tutorial3/




General Django Resources:
Django Website - http://www.djangoproject.com/
Django User Group/Mailing List - http://groups-beta.google.com/group/django-users
Django Developers Group/Mailing List - http://groups-beta.google.com/group/django-developers
Django IRC - irc://irc.freenode.net/django
IRC Logs - http://loglibrary.com/show_page/latest/179




Most of the Content in this reference sheet was gathered from the http://www.djangoproject.com/ website.

Document Version: .1.1
The current document will always be available at: http://www.dobbes.com/

License:
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-nc-sa/2.5/

             Italicized Text – Placeholder names for your object(s)   •   Courier Text – Commands you type in

More Related Content

Viewers also liked

UX, UI, WTF
UX, UI, WTFUX, UI, WTF
UX, UI, WTF
Dustin Williams
 
Online marketing channels
Online marketing channelsOnline marketing channels
Online marketing channelsPradeep Kumar
 
Django ws
Django wsDjango ws
Django ws
jvanveen
 
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
Gigaom
 
Django Worst Practices
Django Worst PracticesDjango Worst Practices
Django Worst Practices
Daniel Greenfeld
 

Viewers also liked (7)

UX, UI, WTF
UX, UI, WTFUX, UI, WTF
UX, UI, WTF
 
Ppc glossary
Ppc glossaryPpc glossary
Ppc glossary
 
Online marketing channels
Online marketing channelsOnline marketing channels
Online marketing channels
 
Django ws
Django wsDjango ws
Django ws
 
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
BACK TO THE FUTURE: DATAFLOW FINALLY COMES OF AGE from Structure 2012
 
The laddo project
The laddo projectThe laddo project
The laddo project
 
Django Worst Practices
Django Worst PracticesDjango Worst Practices
Django Worst Practices
 

Similar to django_reference_sheet

Django
DjangoDjango
Django web framework
Django web frameworkDjango web framework
Django web framework
Abdenour Bouateli
 
Django
DjangoDjango
Django
Ivan Widodo
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
Shrinath Shenoy
 
Django crush course
Django crush course Django crush course
Django crush course
Mohammed El Rafie Tarabay
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
Jason Davies
 
Ant_quick_guide
Ant_quick_guideAnt_quick_guide
Ant_quick_guide
ducquoc_vn
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
railsbootcamp
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
Gordon Forsythe
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]
Devon Bernard
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-python
Deepak Garg
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
DrupalDay
 
GradleFX
GradleFXGradleFX
Build and deploy Python Django project
Build and deploy Python Django projectBuild and deploy Python Django project
Build and deploy Python Django project
Xiaoqi Zhao
 

Similar to django_reference_sheet (20)

Django
DjangoDjango
Django
 
Django
DjangoDjango
Django
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django - basics
Django - basicsDjango - basics
Django - basics
 
Django
DjangoDjango
Django
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Django crush course
Django crush course Django crush course
Django crush course
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Ant_quick_guide
Ant_quick_guideAnt_quick_guide
Ant_quick_guide
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]Effective Python Package Management [PyCon Canada 2017]
Effective Python Package Management [PyCon Canada 2017]
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-python
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
GradleFX
GradleFXGradleFX
GradleFX
 
Build and deploy Python Django project
Build and deploy Python Django projectBuild and deploy Python Django project
Build and deploy Python Django project
 

More from webuploader

Michael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_NetworkingMichael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_Networkingwebuploader
 
cyberSecurity_Milliron
cyberSecurity_MillironcyberSecurity_Milliron
cyberSecurity_Millironwebuploader
 
LiveseyMotleyPresentation
LiveseyMotleyPresentationLiveseyMotleyPresentation
LiveseyMotleyPresentationwebuploader
 
FairShare_Morningstar_022607
FairShare_Morningstar_022607FairShare_Morningstar_022607
FairShare_Morningstar_022607webuploader
 
3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling3_System_Requirements_and_Scaling
3_System_Requirements_and_Scalingwebuploader
 
ScalabilityAvailability
ScalabilityAvailabilityScalabilityAvailability
ScalabilityAvailabilitywebuploader
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summitwebuploader
 
FreeBSD - LinuxExpo
FreeBSD - LinuxExpoFreeBSD - LinuxExpo
FreeBSD - LinuxExpowebuploader
 

More from webuploader (20)

Michael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_NetworkingMichael_Hulme_Banff_Social_Networking
Michael_Hulme_Banff_Social_Networking
 
socialpref
socialprefsocialpref
socialpref
 
cyberSecurity_Milliron
cyberSecurity_MillironcyberSecurity_Milliron
cyberSecurity_Milliron
 
PJO-3B
PJO-3BPJO-3B
PJO-3B
 
LiveseyMotleyPresentation
LiveseyMotleyPresentationLiveseyMotleyPresentation
LiveseyMotleyPresentation
 
FairShare_Morningstar_022607
FairShare_Morningstar_022607FairShare_Morningstar_022607
FairShare_Morningstar_022607
 
saito_porcupine
saito_porcupinesaito_porcupine
saito_porcupine
 
3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling3_System_Requirements_and_Scaling
3_System_Requirements_and_Scaling
 
ScalabilityAvailability
ScalabilityAvailabilityScalabilityAvailability
ScalabilityAvailability
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit7496_Hall 070204 Research Faculty Summit
7496_Hall 070204 Research Faculty Summit
 
Chapter5
Chapter5Chapter5
Chapter5
 
Mak3
Mak3Mak3
Mak3
 
visagie_freebsd
visagie_freebsdvisagie_freebsd
visagie_freebsd
 
freebsd-watitis
freebsd-watitisfreebsd-watitis
freebsd-watitis
 
BPotter-L1-05
BPotter-L1-05BPotter-L1-05
BPotter-L1-05
 
FreeBSD - LinuxExpo
FreeBSD - LinuxExpoFreeBSD - LinuxExpo
FreeBSD - LinuxExpo
 
CLI313
CLI313CLI313
CLI313
 
CFInterop
CFInteropCFInterop
CFInterop
 
WCE031_WH06
WCE031_WH06WCE031_WH06
WCE031_WH06
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 

django_reference_sheet

  • 1. Django Reference Sheet Django Admin SQL Commands Project Setup All the following commands output sql specific to the Create A Project's Directory Structure appname specified in the command and should be django-admin.py startproject projectname run from with the projectname directory. (this command needs to be issued in the directory you w ant the project to be in) django-admin.py sqlinitialdata appname Customize the DB and other setting in the Outputs the initial-data inserts required for Django's projectname/settings/main.py file admin framework. Initialize the DB django-admin.py sql appname django-admin.py init Outputs the table creation statements (this command should be issued in your projectname directory) Set your DJANGO_SETTING_MODULE environment variable django-admin.py sqlall appname Unix: Outputs both the sqlinitialdata and sql data export DJANGO_SETTINGS_MODULE=projectname.settings.main Windows: django-admin.py sqlindexes appname set DJANGO_SETTINGS_MODULE=myproject.settings.main Outputs the the create index statements (you'll probably w ant to set these permanently in your ~/.bashrc file in Unix or your my computer properties in Window s) django-admin.py sqlclear appname Outputs the the drop table statements and the More Details: http://www.djangoproject.com/documentation/tutorial1/ delete statements for deleting the “initialdata”. App Setup Create an App's Directory Structure django-admin.py startapp appname django-admin.py startapp appname (this should be issued in your projectname/apps directory) (this command should be issued in your projectname/apps directory) More Details: Setup App's models in the projectname/apps/appname/models/appname.py http://www.djangoproject.com/documentation/ file tutorial1/#activating-models Template Syntax Add the App to the INSTALLED_APPS in projectname/settings/main.py There are two types of syntax: {% something %} - For tags which include blocks Install the App in the DB and functional items like loops, if statements, and django-admin.py install appname includes. (this command should be issued in your projectname directory) {{ variable }} - For variable insertion where More Details: “variable” is replaced with it's value. http://www.djangoproject.com/documentation/tutorial1/#creating-models URL Dispatcher Sample Config Files Sample projectname/settings/urls/main.py file from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^weblog/', include('django_website.apps.blog.urls.blog')), (r'^documentation/', include('django_website.apps.docs.urls.docs')), (r'^comments/', include('django.contrib.comments.urls.comments')), (r'', include('django.conf.urls.flatfiles')), ) Sample projectname/apps/blog/urls/main.py file from django.conf.urls.defaults import * info_dict = { 'app_label': 'blog', 'module_name': 'entries', } urlpatterns = patterns('django.views.generic.date_based.', (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$', 'archive_day', info_dict), (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict), (r'^(?P<year>d{4})/$', 'archive_year', info_dict), (r'^/?$', 'archive_index', info_dict), ) Italicized Text – Placeholder names for your object(s) • Courier Text – Commands you type in
  • 2. Template Filters add - Adds the arg to the value random - Returns a random item from the list addslashes - Adds slashes, for passing strings to JavaScript. removetags - Removes a space separated list of [X]HTML Capfirst - Capitalizes the first character of the value tags from the output center - Centers the value in a field of a given width rjust - Right-aligns the value in a field of a given width, cut - Removes all values of arg from the given string Argument: field size date - Formats a dateto the given format using “now” format slice - Returns a slice of the list. default - If value is unavailable, use given default slugify - Converts to lowercase, removes non-alpha chars dictsort - Takes a list of dicts, returns that list sorted by the and converts spaces to hyphens property given in the argument. stringformat - Formats the variable according to the dictsortreversed - Takes a list of dicts, returns that list sorted in argument, a string formatting specifier. This specifier uses reverse order by the property given in the argument. Python string formating syntax, with the exception that the divisibleby - Returns true if the value is divisible by the argument leading quot;%quot; is dropped. escape - Escapes a string's HTML striptags - Strips all [X]HTML tags filesizeformat - Format the value like a 'human-readable' file. time - Formats a time according to the given format (same First - Returns the first item in a list as the now tag). fix_ampersands - Replaces ampersands with &amp; entities timesince - Formats a date as the time since that date floatformat - Displays a floating point number as 34.2 (with one (i.e. quot;4 days, 6 hoursquot;) decimal places) - but only if there is a decimal point. title - Converts a string into titlecase get_digit - Given a whole number, returns the requested digit of it, truncatewords - Truncates a string after a certain number where 1 is the right-most digit, 2 is the second-right-most digit, etc. of words. Argument: Number of words to truncate after. Returns the original value for invalid input, unordered_list - Recursively takes a self-nested list and join - Joins a list with a string, like Python's str.join(list) returns an HTML unordered list -- WITHOUT opening and length - Returns the length of the value - useful for lists closing <ul> tags. length_is - Returns a boolean of whether the value's length is the upper - Converts a string into all uppercase argument urlencode - Escapes a value for use in a URL linebreaks - Converts newlines into <p> and <br />s urlize - Converts URLs in plain text into clickable links linebreaksbr - Converts newlines into <br />s urlizetrunc - Converts URLs into clickable links, truncating linenumbers - Displays text with line numbers URLs to the given character limit. Argument: Length to ljust - Left-aligns the value in a field of a given width, Argument: truncate URLs to. field size wordcount - Returns the number of words lower - Converts a string into all lowercase wordwrap - Wraps words at specified line length. make_list - Returns the value turned into a list. Argument: number of words to wrap the text at. phone2numeric - Takes a phone number and converts it in to its yesno - Given a string mapping values for true, false and numerical equivalent (optionally) None, returns one of those strings according to pluralize - Returns 's' if the value is not 1. the value. Sample argument quot;yeah,no,maybequot; returns yeah pprint - A wrapper around pprint.pprint -- for debugging. for true, no for false, and maybe for none. Template Tag Reference block – Defines an area that the content can be inserted into. if – Evaluates for true or false {% block content %}Default Content{% endblock %} {% if athlete %}{{ athlete }}{% endif %} comment - {% comment %}{% endcomment %} (if statements can have “not” and “or”, but are not allow ed to have “and”) cycle – Rotates through items ifchanged – Outputs it's content if different from last loop. <tr class=quot;{% cycle red,blue as colors %}quot;>..</tr> {% ifchanged %}{{ name }}{% endifchanged %} <tr class=quot;{% cycle colors %}quot;>...</tr> (code w ould be w ithin for loop) ifnotequal – Checks for equality debug – Outputs a bunch of debug info {% debug %} {% ifnotequal v1 v2 %}hi{% endifnotequal %} extends – Inherits from another template load – loads a custom tag set {% load comments %} {% extends quot;basequot; %} now – Outputs current date {% now quot;jS F Y H:iquot; %} (leave off the .html for the template name) filter – Applies the specified filter(s) to the content in between (formatting matches php's date function for the most part) {% filter lower %}Lowercase this{% endfilter %} regroup –Regroup a list of like objects by an attribute firstOf – Outputs the first true variable, or nothing if all are false. {% regroup people by gender as grouped %} {% firstof var1 var2 var3 %} ssi – Includes a file for – Loop through list item {% ssi /home/html/side.html parsed %} {% for athlete in athlete_list %} (if the option passed “parsed it w ill be treated as a template) templatetag – Used to escape template tags {{ athlete.name }} {% templatetag openblock %} {% endfor %} (arguments open/closeblock and open/closevariable) forloop.counter = current loop iteration starting at 1 widthratio – Calculates the ratio of a given value to a forloop.counter0 = current loop iteration starting at 0 forloop.first = True if first time through loop maximum value, and then applies that ratio to a constant. forloop.last = True if this is the list time through the loop {% widthratio this_value max_value 100 %} forloop.parentloop = Parentloop counter (???) Italicized Text – Placeholder names for your object(s) • Courier Text – Commands you type in
  • 3. Sample Template {% extends quot;basequot; %} {% block title %}{{ title|title }}{% endblock %} {% block intro %} Default Intro Copy that can be replaced by templates extending this one {% endblock %} {% block content %} {% for entry in blog_entries %} {% ifchanged %}<h1>{{ entry.pub_date|date”F, y” }}</h1>{% endifchanged %} <h2>{{ entry.title }}</h2> <p> {{ entry.body|escape|urlizetrunc:quot;40quot;|linebreaks}}</p> {% endfor %} {% endblock %} Additional Template Resources: http://www.djangoproject.com/documentation/templates/ http://www.djangoproject.com/documentation/tutorial3/ General Django Resources: Django Website - http://www.djangoproject.com/ Django User Group/Mailing List - http://groups-beta.google.com/group/django-users Django Developers Group/Mailing List - http://groups-beta.google.com/group/django-developers Django IRC - irc://irc.freenode.net/django IRC Logs - http://loglibrary.com/show_page/latest/179 Most of the Content in this reference sheet was gathered from the http://www.djangoproject.com/ website. Document Version: .1.1 The current document will always be available at: http://www.dobbes.com/ License: Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License http://creativecommons.org/licenses/by-nc-sa/2.5/ Italicized Text – Placeholder names for your object(s) • Courier Text – Commands you type in