Sugree

Main menu

  • About
    • Self
  • Project
    • GT200
    • GeoPin
    • Mitter
    • Red Mob
    • Thairath Breaking News
    • jibjib
    • microblog-purple
    • English
    • Thai

Django - Hello, World!

Submitted by sugree on Thu, 09/11/2008 - 00:27
  • Django
  • Python
  • Thai

คราวที่แล้วเป็น Hello, World! แบบครึ่งๆ กลางๆ ยังไม่เห็นคำที่ควรจะเห็น เพราะเหนื่อยแล้ว เลยต้องมาต่อภาค 2 ให้จบ ก่อนอื่นเข้าไปในโปรเจคก่อน

cd ~/work/git/django66/samplesite

แล้วสร้างแอ๊พ

python manage.py startapp helloworld

จะได้เพิ่มมาดังนี้

helloworld/
helloworld/__init__.py
helloworld/views.py
helloworld/models.py

เป็นโค้ดโล่งๆ ไม่มีอะไรในกอไผ่ ตอนนี้เราแค่อยาก Hello, World! อย่างอื่นไม่สน พุ่งตรงไปที่ helloword/views.py ดีกว่า

from django.http import HttpResponse
 
def helloworld(request):
    return HttpResponse('Hello, World!')

ต่อมาก็เอาไปใส่ใน urls.py เป็นการใส่ routing แบบง่ายๆ

from django.conf.urls.defaults import *
 
urlpatterns = patterns('',
    (r'^$', 'samplesite.helloworld.views.helloworld'),
)

เสร็จแล้ว ได้เวลาทดสอบ

python manage.py runserver

แล้วเข้าไปดูผลที่ http://localhost:8000/

Roti (alpha) thinks you may like these:
  • MVC in Django
  • Django 66 - Django Thailand
  • Simple template in Django
  • Django - Hello, World!
  • Loop in template
by chanwit (not verified) on Fri, 09/12/2008 - 07:03 #501

controller ใน django หน้าตาเป็นไงครับ?

views.py นี่ดูเหมือนจะเป็นตัวจัดการ view อะไรซักอย่าง ? หน้าตาโครงสร้างมัน ถ้าเทียบกับ Java ก็ออกไปทาง servlet

  • reply
by Anonymous (not verified) on Thu, 05/21/2009 - 09:06 #969

Tnx for the code HelloWrold

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode> <pre>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <html>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <html>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use Markdown syntax to format and style the text. Also see and Markdown Extra for tables, footnotes, and more.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.

More information about formatting options

Popular Tags

Android BarCamp BarCampBangkok BarCampBangkok2 Book Django Drupal Education Family Google Hardware Hardy Health Interview Java jibjib Joke Life microblog-purple OpenOffice.org OpenSource Podcast Python Review SoC Social Network Trip Twitter Ubuntu Weekly Suki
more tags

Powered By

debian
apache
drupal
drupal.in.th
openfreehost
inox
feedburner

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