0% found this document useful (0 votes)
574 views1 page

Templateless Django Cheat Sheet 2016-04-14

Django Cheat Sheet

Uploaded by

Ahobusse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
574 views1 page

Templateless Django Cheat Sheet 2016-04-14

Django Cheat Sheet

Uploaded by

Ahobusse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

TemplatelessDjangoCheatSheet

CommandLine Urls Models(cont')


CreateProject GET,POSTUrl url(r'^smth/?$',views.method) TextField TextField(..)
$djangoadminstartproject{projectname} GET,PUT,DELETE url(r'^smth/(?P[09]+)/?$', EmailField EmailField(max_length=300,..)
CreateApp Url views.method)
URLField URLField(max_length={..},..)
$pythonmanage.pystartapp{appname} ImportCRSF fromdjango.views.decorators.csrf DateField DateField(auto_now=True,..);
Exempt(not importcsrf_exempt DateTimeField(..)
CreateMigrationFiles(DBnotyetaffected)
$pythonmanage.pymakemigrations{appname} recommendedfor IntegerField IntegerField(..)
PerformmigrationonDB production) DecimalField DecimalField(max_digits=3,
$pythonmanage.pymigrate decimal_place=2,..)
Views
FloatField FloatField(..)
Runtests
ViewDeclaration defview_method(request):
Onetoone OneToOneField(someModel,
$pythonmanage.pytest
JSONRequestData request.data['json_field'] relationship on_delete={..},..)
RunSingleTest
$pythonmanage.pytest{app_name}.tests.{TestClass}.
Getuser request.user Manytoone ForeignKey(someModel,on_delete=
relationship {..},..)
{test_method} RequestMethod request.method
Runserver RequestCookies cookies_dict=request.COOKIES ManytoMany ManyToManyField(someModel,..)
$pythonmanage.pyrunserver Response returnHttpResponse(data, relationship
content_type={..},status_code=
RunserverallowingallIPs MakingQueries
{..})
$pythonmanage.pyrunserver0.0.0.0:{port_number}
ResponseHeader response=HttpResponse(..); Createobject obj=Model.objects.create(
response['header']=value field=val,..);
ImportantFiles obj.save()
Response'sCookie HttpResponse(..).set_cookie
Webappsettings {project_name}/settings.py ('key','value') Getsingleobject Model.objects.get(field=val,..)
(database,apps,...) JSONResponse returnJsonResponse({'key': Filterobjects Model.objects.filter(field=val,..)
Urls/Routes {project_name}/urls.py (subclassofHTTP 'val'})
(returnsqueryset)
(maps"views"to Response)
[canalsohavesuburlsfilesvia Advancefiltering Model.objects.filter(
urls) "include(*)"] field__{whereop}=..)
Models
Views/Controllers {app_name}/views.py Getallobjectsofa Model.objects.all()
ModelDeclaration fromdjango.dbimportmodels model
(retrievedatavia
"models"and classSomeStuff(models.Model): Excludeobjects Model.objects.filter(..)
rendersresponse) .exclude(field=val,...)
FieldsDeclaration models.SomeField(param=val)
Models {app_name}/models.py Checkobjectsexists Model.objects.filter(..)
CommonField null=True;blank=True; .exists()
(createscolumnsfor Options choices=(('CD','Code'));
default="default_value"; Updateobject obj['key']='new_val';
tables) obj.save()
primary_key=True;unique=
Test {app_name}/tests.py
True; Addmanytomany obj.many_fields.add(some_obj)
BooleanField BooleanField(**options) objects
NotableSettings
CharField CharField(max_length={..},..) Addmanytoone one_obj.manymodelname_set
INSTALLED_APPS,DATABASES,BASE_DIR,LOGGING,DEBUG, .add(some_obj)
ALLOWED_HOSTS,DATABASE_ROUTERS,APPEND_SLASH, objects
CORS_ORIGIN_ALLOW_ALL,AUTHENTICATION_BACKENDS Deleteobject obj.delete()

Copyright2016byYaoHongKok Createdon:April9,2016

You might also like