ãã¥ã¼ã®ãã³ã¬ã¼ã¿Â¶ Django ã«ã¯ãHTTP ã®æ§ã ãªæ©è½ããã¥ã¼ã«é©ç¨ããããã®ããã¤ãã®ãã³ã¬ã¼ã¿ ãç¨æããã¦ãã¾ãã HTTP ã¡ã½ããã®å¶é¶ django.views.decorators.http å ã®ä»¥ä¸ã®ãã³ã¬ã¼ã¿ã¯ãªã¯ã¨ã¹ãã¡ã½ãã ã«ããã¢ã¯ã»ã¹å¶éã«ä½¿ç¨ã§ãã¾ãããã®ãã³ã¬ã¼ã¿ã¯ãæ¡ä»¶ãæºããã¦ããªã å ´å django.http.HttpResponseNotAllowed ãè¿ãã¾ãã require_http_methods(request_method_list)¶ ç¹å®ã®ãªã¯ã¨ã¹ãã¡ã½ããã®ã¿ã許å¯ããããã®ãã³ã¬ã¼ã¿ã®å©ç¨æ¹æ³ã§ã: from django.views.decorators.http import require_http_methods @require_http_methods(["GET", "POST"]) def my_v
QuerySet API reference¶ ãã®ããã¥ã¡ã³ãã§ã¯ãQuerySet API ã®è©³ç´°ã説æãã¦ãã¾ããã¢ã㫠㨠ãã¼ã¿ãã¼ã¹ã¯ã¨ãª ã¬ã¤ãã«ãã説æãåæã¨ãã¦ãã¾ãã®ã§ããã®ããã¥ã¡ã³ããèªãåã«ãã® 2 ã¤ãèªãã§ãããæ¹ãããã§ãããã ãã®ããã¥ã¡ã³ãå ¨ä½ãéãã¦ããã¼ã¿ãã¼ã¹ã¯ã¨ãªã¬ã¤ã ã§ä½¿ã£ã Weblog ã¢ãã«ä¾ ã使ç¨ãã¾ãã When QuerySets are evaluated¶ å é¨çã«ã QuerySet ã¯å®éã«ãã¼ã¿ãã¼ã¹ã«ã¢ã¯ã»ã¹ãããã¨ãªããæ§ç¯ããã£ã«ã¿ãã¹ã©ã¤ã¹ãããã¦åºæ¬çã«ä»ã«æ¸¡ããã¾ããããªããã¯ã¨ãªã»ãããè©ä¾¡ããããã«ä½ãããªãéããå®éã®ãã¼ã¿ãã¼ã¹ã¸ã®ã¢ã¯ã»ã¹ã¯çºçãã¾ããã ããªãã¯æ¬¡ã®ãããªæ¹æ³ã§ QuerySet ãè©ä¾¡ãããã¨ãã§ãã¾ã: ã¤ãã¬ã¼ã·ã§ã³ã QuerySet ã¯ã¤ãã©ãã«ã§ãåãã¦ã¤ãã¬ã¼ã
Django ã¯ã¦ã¼ã¶ã¼èªè¨¼ã·ã¹ãã ãæè¼ãã¦ãã¾ããã¦ã¼ã¶ã¼ã¢ã«ã¦ã³ããã°ã«ã¼ãããã¼ããã·ã§ã³ãããã¦Cookieãã¼ã¹ã®ã¦ã¼ã¶ã¼ã»ãã·ã§ã³ãå¶å¾¡ãã¾ãããã®ããã¥ã¡ã³ãã®ãã®ã»ã¯ã·ã§ã³ã§ã¯ãããã©ã«ãã®å®è£ ãã©ãæ©è½ããããã¾ãããªãã®ããã¸ã§ã¯ãã®ãã¼ãºã«å¯¾å¿ãããããã® æ¡å¼µã¨ã«ã¹ã¿ãã¤ãº ã®æ¹æ³ã説æãã¦ãã¾ãã æ¦è¦Â¶ Django ã®èªè¨¼ã·ã¹ãã ã¯ãèªè¨¼ã¨æ¨©éã®ä¸¡æ¹ãæ±ãã¾ããç°¡åã«è¨ãã¨ãèªè¨¼ã¯ã¦ã¼ã¶ã¼ã誰ã§ããããç«è¨¼ãã権éã¯ç«è¨¼ãããã¦ã¼ã¶ã¼ãä½ããããã¨ã許ããã¦ãããã決å®ãã¾ããããã§ã¯ãèªè¨¼ã¨ããç¨èªã¯ä¸¡æ¹ã®ã¿ã¹ã¯ãæãããã«ä½¿ããã¾ãã èªè¨¼ã·ã¹ãã ãæ§æãããã®ã¯ä»¥ä¸ã®éãã§ã: ã¦ã¼ã¶ ãã¼ããã·ã§ã³: ã¦ã¼ã¶ãç¹å®ã®ã¿ã¹ã¯ãå®è¡ã§ãããã©ãããæå®ãããã¤ã㪠(yes/no) ãã©ã° ã°ã«ã¼ã: è¤æ°ã®ã¦ã¼ã¶ã¼ã«ã©ãã«ã¨ãã¼ããã·ã§ã³ãä»ä¸ããä¸è¬
ã¢ãã«ãã£ã¼ã«ããªãã¡ã¬ã³ã¹Â¶ ãã®ããã¥ã¡ã³ãã«ã¯ãDjango ãæä¾ãã field options 㨠field types ãå«ããField ã®å ¨ã¦ã® API ãªãã¡ã¬ã³ã¹ãè¨è¼ããã¦ãã¾ãã åè åãä»ãã®ãã£ã¼ã«ãã§ã¯ç®çãéãããã¨ãã§ããªãå ´åãdjango-localflavor (ããã¥ã¡ã³ã) ã試ããã¨ãã§ãã¾ããããã«ã¯ç¹å®ã®å½ãæåã«æç¨ãªã³ã¼ãé¨åããå種åãæãããã¦ãã¾ãã ããã«ãç°¡åã« ããªãèªèº«ã®ç¬èªã®ã¢ãã«ãã£ã¼ã«ããä½ããã¨ãã§ãã¾ãã 注é æè¡çã«ã¯ããããã®ã¢ãã«ã¯ django.db.models.fields å ã§å®ç¾©ããã¦ãã¾ããå©ä¾¿æ§ã®ãã django.db.models ã«ã¤ã³ãã¼ãããã¦ãã¾ã; æ¨æºçãªæ £ç¿ã§ã¯ãfrom django.db import models ã使ã£ã¦ããã£ã¼ã«ãã models.<Foo>
ã¯ã¨ãªãä½æã㶠ä¸åº¦ ãã¼ã¿ã¢ãã« ãä½æããã°ãDjango ã¯ãã¼ã¿ãªãã¸ã§ã¯ãã®ä½æãåå¾ãæ´æ°ããã³åé¤ãè¡ããããã«ãã¼ã¿ãã¼ã¹ãæ½è±¡åãã API ãèªåçã«æä¾ãã¾ããæ¬ããã¥ã¡ã³ãã§ã¯ãã® API ãã©ã®ããã«ç¨ãããã説æãã¾ããå¤æ§ãªã¢ãã«æ¢ç´¢ãªãã·ã§ã³å ¨ã¦ã«é¢ãã詳細ã«ã¤ãã¦ã¯ ãã¼ã¿ã¢ãã«ã®é ç® ãåç §ãã ããã æ¬é ( ããã³åç §ããæç« )ã§ã¯ã以ä¸ã«å®ç¾©ãããã¦ã§ããã°ã¢ããªã±ã¼ã·ã§ã³ãæ§æããã¢ãã«å®ç¾©ãå©ç¨ãã¾ã: from django.db import models class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def __str__(self): return self.name class Autho
Self-referencing many-to-many through January 16, 2010 18:36 / django many-to-many python / 3 comments Django's ManyToMany through attribute allows you to describe relationships between objects. I've written a post about this - (Describing Relationships, Django's ManyToMany Through) - and so I won't cover here the details of its implementation or usage. What I want to talk about in this post is ho
ã¢ãã«Â¶ ã¢ãã«ã¯ããã¼ã¿ã«é¢ããå¯ä¸ãã¤æ±ºå®çãªæ å ±æºã§ããããªããä¿æãããã¼ã¿ãå¿ è¦ã¨ãããã£ã¼ã«ãã¨ãã®åä½ãå®ç¾©ãã¾ããä¸è¬çã«ãåã¢ãã«ã¯åä¸ã®ãã¼ã¿ãã¼ã¹ã®ãã¼ãã«ã«å¯¾å¿ä»ãããã¾ãã åºæ¬: ã¢ãã«ã¯åã Python ã®ã¯ã©ã¹ã§ãã django.db.models.Model ã®ãµãã¯ã©ã¹ã§ãã ã¢ãã«ã®å±æ§ã¯ããããããã¼ã¿ãã¼ã¹ã®ãã£ã¼ã«ãã表ãã¾ãã ãããå ¨ã¦ãç¨ãã¦ãDjango ã¯ãã¼ã¿ãã¼ã¹ã«ã¢ã¯ã»ã¹ããèªåçæããã API ãæä¾ãã¾ãã ã¯ã¨ãªãä½æãã ãåç §ãã¦ãã ããã from django.db import models class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_leng
ãã¡ãããªã¹ã¹ã¡ãã¾ãã 以ä¸ã®è¨äºã¯å¤ãã§ãã Django ã® User ã¢ãã«ã¯ããã®ã¾ã¾ç¶æ¿ãããã¨ã¯ã§ãã¾ããã ãã®çç±ã¯ User ã¢ãã«ã¯ Auth ã¨ããããã©ã«ãã§ã¤ãã¦ããã¢ããªå ã®ã¢ãã«ã ããã§ãããªã®ã§ãã¢ããªå ã®ã¢ãã«ãæ¡å¼µãã¦ãããã°ããã®ã§ããããã¨ã«ãªãæ©è½ãªã®ã§ç´æ¥ã¯è§¦ããã¦ããç¡ãã¨è¨ã訳ã§ãã 解決ç Case 1. Django 1.4 以åã®å ´å â User 㨠OneToOneField ã®é¢ä¿ã«ããã¢ãã«(ex, UserProfile)ãä½æããã Case 2. Django 1.5 以éã®å ´å â AbstractUser ãç¶æ¿ãããã¢ãã«ã使ãã Case 1. Django 1.4 以åã®å ´å ããæ¹ã¨ãã¦ã¯ã Step1. User 㨠OneToOneField ã®é¢ä¿ã«ããã¢ãã«(ex, UserProfile)ãä½æãã
éçãã¡ã¤ã« (ç»åãJavaScriptãCSS ãªã©) ã管çã㶠ã¦ã§ããµã¤ãã§ã¯ãµã¤ããç»åã JavaScriptãCSS ãªã©ã®è¿½å ã®ãã¡ã¤ã«ãé ä¿¡ããå¿ è¦ãããã¾ããDjango ã§ã¯ããããããã¡ã¤ã«ã®ãã¨ããéçãã¡ã¤ã« (static files)ãã¨å¼ãã§ãã¾ããéçãã¡ã¤ã«ã®ç®¡çãç°¡åã«ããããã«ãDjango 㯠django.contrib.staticfiles ãæä¾ãã¦ãã¾ãã ãã®ãã¼ã¸ã§ã¯ãããããéçãã¡ã¤ã«ã®é ä¿¡ã®ä»æ¹ã«ã¤ãã¦èª¬æãã¾ãã éçãã¡ã¤ã«ã®è¨å®Â¶ django.contrib.staticfiles ãè¨å®ãã¡ã¤ã«ã® INSTALLED_APPS ã«å«ã¾ãã¦ãããã¨ã確èªãã¦ãã ããã è¨å®ãã¡ã¤ã«ã®ä¸ã§ãSTATIC_URL ãè¨å®ãã¾ãããã¨ãã°ã次ã®ããã«ãªãã¾ãã
from django import forms class KakikomiForm(forms.Form): name = forms.CharField() email = forms.EmailField() body = forms.CharField(widget=forms.Textarea) ä¸ã®ã³ã¼ãã®ã¾ã¾ããµããããããã¨ã©ã®ããã«ãªãã確èªãã¾ãã ä½ãå ¥åããã«ãã©ã¼ã ããµããããããã¨ãããã©ã«ãã§ã¯å ¨ã¦å¿ é å ¥åé ç® (required=True) ã§ããããå ¥åãä¿ãã¨ã©ã¼ã¡ãã»ã¼ã¸ã表示ããã¾ãã å ¥åé ç®ãå¿ é é ç®ã§ã¯ãªããä»»æã®å ¥åé ç®ã«ããã«ã¯ã次ã®ããã« required=False ã¨ãã¾ãã from django import forms class KakikomiForm(forms.Form): name = forms.CharField
Django ã®æ±ç¨ãã¥ã¼ã®ä½¿ãæ¹ã調ã¹ãããã«å ¬å¼ããã¥ã¡ã³ããèªãã ãã§ãããä»æ´ãªãã Django1.3 ã§æ±ç¨ãã¥ã¼ãé¢æ°ããã¯ã©ã¹ã«å¤ãã£ã¦ãããã¨ãç¥ãã¾ããã1.3 ãªãªã¼ã¹ã¯ä»å¹´ã®3æ23æ¥ã ããã8ãæè¿ãç¥ããªãã£ããã¨ã«ãªãããªãããºã«ã·ã¤ã Class-based views | Django documentation | Django é¢æ°çã®æ±ç¨ãã¥ã¼ãã¾ã 使ããã¿ããã§ãããããã¥ã¡ã³ããè¦ãæããã¨ãã¯ã©ã¹ãã¼ã¹ã®æ¹ã便å©ããã 試ãã«ããã¤ãã®ãã¥ã¼ãã¯ã©ã¹ãã¼ã¹ã®æ±ç¨ãã¥ã¼ã使ã£ã¦å®è£ ãã¦ã¿ã¾ãããç¾å¨éçºãã¦ãããµã¼ãã¹ã®ã³ã¼ãããæç²ã from django.views.generic import ListView class UserPostListView(ListView): # ãã¥ã¼ãæç»ã«ä½¿ããã³ãã¬ã¼ããæå® template_
ããã«ã¡ã¯ãç¸å¤ãããæãæ¥ãç¶ãã¾ããããçä¼ã¿ã¨ãããã¨ã§æ´æ°ããä¼ã¿ãã¦ãã¾ããããåéãã¾ãã ãã¦ä»æ¥ã¯Djangoã§ãã¦ã¼ã¶ã¼èªè¨¼ãè¡ãæ¹æ³ã«ã¤ãã¦æ¸ãã¦ããã¾ãã 注ï¼Djangoã¯v1.6ã§ã Samplesï¼ GitHub ç·¨éåã®ããã¸ã§ã¯ãï¼before ç·¨éå¾ã®ããã¸ã§ã¯ãï¼after ç¹å®ãã¼ã¸ã¢ã¯ã»ã¹æã«ã¦ã¼ã¶ã¼èªè¨¼ãæ±ããããã«è¨å®ãã ç¹å®ã®ãã¼ã¸ã«ã¦ã¼ã¶ã¼èªè¨¼ä¿è·ãããã¾ããDjangoã«ã¯ã¦ã¼ã¶ã¼èªè¨¼ç¨ã®ãã¼ã«ãç¨æããã¦ãã¾ããsettings.pyã®INSTALLED_APPSã«ããã©ã«ãã§ã¯æ¬¡ã®ã¢ããªãå«ã¾ãã¦ããã¯ããªã®ã§ãæç¡ã確èªãã¦ããã¾ãã 'django.contrib.auth' ããç¡ããã°è¿½è¨ããã°OKã§ãã ããããã¼ã¸ã«ã¦ã¼ã¶ã¼èªè¨¼ä¿è·ãããã ã¾ãã¯ãããããã¼ã¸ã«ã¦ã¼ã¶ã¼èªè¨¼ä¿è·ãããã¦ã¿ã¾ããä¸è¨4ãã¡ã¤ã«ãè¨è¿°ãã¦ããã¾
Django ã¯ã DRY (Don't Repeat Yourself) ã®ç²¾ç¥ Python 製㮠MVC ãã¬ã¼ã ã¯ã¼ã¯ï¼All-in-One & Pluggableï¼ BSDã©ã¤ã»ã³ã¹ã® OSS O/R ãããã³ã° API å¼·åãªãã³ãã¬ã¼ãã¨ã³ã¸ã³ ã¦ã¼ã¶èªè¨¼ã»ã»ãã·ã§ã³ å½éå ãªã©ã®ç¹å¾´ãåãã Webãã¬ã¼ã ã¯ã¼ã¯ã§ãã Python 製㮠Webãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦ã¯ãç¾å¨ã»ã¼ä¸æã«ãªã£ã¦ããã¨è¨ã£ã¦ãããã®ã§ã¯ãªãã§ãããããå®é使ã£ã¦ãã¦ãã足ããªãã¨ããã¯ãã¾ãç¡ãããã«æãã¾ãã ç¾æç¹ã§ã®ææ°ãã¼ã¸ã§ã³ã¯ã1.6.5 ã§ããããããã 1.7 ã«ãã¼ã¸ã§ã³ã¢ããããäºå®ã¨ãªã£ã¦ãã¾ãã ï¼2014/9/3 追è¨ï¼9/2 ã«ããããããã¼ã¸ã§ã³ 1.7 ããªãªã¼ã¹ããã¾ããï¼ï¼ ï¼åèï¼ The Web framework for perfectionists w
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}