Sugree

Main menu

  • About
    • Self
  • Project
    • Mitter
    • jibjib
    • microblog-purple
    • English
    • Thai

Django

Loop in template

Submitted by sugree on Wed, 09/24/2008 - 11:17
  • Django
  • Python
  • Thai

อยากทำ Hangman แต่ยังไม่มีเวลาว่างยาวพอที่จะเริ่ม ช่วงนี้เลยเปลี่ยนวิธีทำงาน ลด time quantum ลงด้วย rtm แทนทึ่จะเขียนทีละ 1 ชั่วโมงก็ลดให้เหลือแค่ 15 นาที หัวข้อก็จะสั้นหน่อย

วันนี้เริ่ม Hangman ซะที

python manage.py startapp hangman
Roti thinks you may like these (alpha)
  • Loop in template
  • Simple template in Django
  • MVC in Django
  • Django - Hello, World!
  • Django 66 - Django Thailand
  • Add new comment
  • Read more

Static files in Django

Submitted by sugree on Sat, 09/20/2008 - 09:27
  • Django
  • Python
  • Thai

ในตอนแรกของการสร้าง app สำหรับอัพโหลด มีขั้นตอนสำหรับการใช้ไฟล์ภายนอกไว้หน่อยนึง นี่เป็นหนึ่งในสิ่งที่จำเป็นสำหรับการทำ Hangman วันนี้ก็มาขยายความกันนิดนึง

ใน Django มีวิธีรับมือกับไฟล์ภายนอกที่อยู่นิ่งๆ ไม่เปลี่ยนแปลงอยู่ในขั้นเกือบเทพ เหมาะกับ CDN มาก ใช้ก็ง่าย แค่ระบุ url ใน settings.py

MEDIA_URL = '/static_media/'

เวลาใช้จริงอาจจะเปลี่ยนเป็น url เต็มๆ อย่าง http://static.domain.com/ ได้ไม่ยาก

Roti thinks you may like these (alpha)
  • Simple template in Django
  • MVC in Django
  • Django - Hello, World!
  • Loop in template
  • Django 66 - Django Thailand
  • 2 comments
  • Read more

Session in Django

Submitted by sugree on Wed, 09/17/2008 - 12:08
  • Django
  • Python
  • Thai

ก่อนที่จะเริ่มทำ Hangman ยังมีเรื่องที่ต้องรู้อีกนิดนึง อย่างแรกก็คือ Session ทำมาตั้งนานยังไม่ได้พูดถึงซักนิด ใน Django นั้น session เป็นของเสริม ไม่ใช้ก็ไม่ต้องใส่ ช่วยได้นิดหน่อย จึงต้องพูดถึงนิดนึง เริ่มจาก middleware ต้องมี django.contrib.sessions.middleware.SessionMiddleware ใน MIDDLEWARE_CLASSES

Roti thinks you may like these (alpha)
  • Simple template in Django
  • MVC in Django
  • Django - Hello, World!
  • Loop in template
  • Django 66 - Django Thailand
  • Add new comment
  • Read more

URL dispatching in Django

Submitted by sugree on Tue, 09/16/2008 - 00:34
  • Django
  • Python
  • Thai

คราวก่อนคงสังเกตุเรื่องขัดตาใน urls.py ที่น่ารำคาญไปหน่อย ต้องมานั่งเขียน re เพื่อจับคู่กับ view จริงๆ แล้วที่เห็นนั่นเป็นแบบเขียนเล่น เขียนง่ายๆ เวลาใช้จริงเราจะโยนหน้าที่พวกนี้กระจายให้แต่ละ app ในที่นี้ก็คือ helloworld ซึ่งควรจะจัดการกับ url ของตัวเองทั้งหมดด้วยตนเอง นั่นแปลว่า ทำ app เสร็จก็ยกไปใช้ที่โปรเจคอื่นได้ทันที ไม่ต้องมานั่งทำ urls.py เอง แต่ถ้าอยากเปลี่ยน url ก็ทำได้เช่นกัน

วิธีทำก็แสนง่าย ย้าย urls.py ไปเป็น helloworld/urls.py โดยไม่มีอะไรเปลี่ยนแปลง

from django.conf.urls.defaults import *
 
urlpatterns = patterns('',
    (r'^$', 'samplesite.helloworld.views.index'),
    (r'^(?P<name>.*)$', 'samplesite.helloworld.views.entity'),
)
Roti thinks you may like these (alpha)
  • Simple template in Django
  • MVC in Django
  • Django - Hello, World!
  • Loop in template
  • Django 66 - Django Thailand
  • Add new comment
  • Read more
  • 1
  • 2
  • 3
  • next ›
  • last »

Popular Tags

Assumption BarCamp BarCampBangkok BarCampBangkok2 BarCampBkk2 ChipIn Django Drupal DrupalCamp DrupalCampBangkok Education Family Google Hardware Hardy Health Java jibjib Joke OpenOffice.org OpenSource Podcast Python Review SoC Social Network Trip Twitter Ubuntu Weekly Suki
more tags

Powered By

debian
apache
drupal
drupal.in.th
feedburner

© 2007-2008 Sugree Phatanapherom. Creative Commons [Feed Content / Comment]
RoopleTheme