ผมหัดทำเว็บด้วย django ทำงุๆปลาแบบรันหน้าเว็บ โชว์ คำพูดหรือเช็ค สคริป ได้เฉยๆครับแต่
งงกับการเขียนเทมเพลต ครับ คือยังสับสนกับปัญหาของตัวเองอยู่ พอดีผมเห็น ในเว็บที่เขาสอนการใช้ โหมด admin ทำให้ง่ายต่อการสร้างเว็บครับ แต่ทำแล้วก็ยังงงๆ อยู่รบกวนผู้รู้ช่วยชี้แนะด้วยครับ
ขอบคุณครับ

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

คือผมศึกษา django ผ่าน พวก e-book Packt.Publishing.Learning.Website.Development.with.Django.Mar.2008 หนะครับ ผมพอเข้าใจกับการทำงาน แล้วครับแต่ติดตรง การทำลอกอินหนะครับ พวกให้สามารถลอกอินเข้าใช้แล้วก็สมัครสมาชิกแต่พอไปศึกษาที่ http://www.djangoproject.com/documentation/0.96/
authentication/. ก็ยิ่งรู้เรื่องเลยครับเลยอยากหาคนชี้แนะการ ทำลอกอินพวกสมัครมาชนิกด้วยครับ

ขอบคุณมากครับ พอดีผมเป็นพวกไม่ค่อยจะไปอ่านจากเว็บของ ดีจังโก้เท่าไหร่ครับ ชอบ ไปอ่านพวก อีบุค แล้วลุยดูหนะครับ ขอให้ ลิ้งที่พี่ๆให้มา ช่วยผมให้สำเร็จเถอะครับสาธุ ตอนนี้ ผมเขียน ใน ลินุกหนะครับ พอดีจะเขียนทำโปรเจ็ค ควบคู่กับ libpcap หนะครับ กะจะดึงข้อมูลจาก logging จาก libpcap มาโชว์ในเว็บหนะครับ ขอบคุณครับ

หลังจากได้ลองเขียนตาม tutorial 1, 2, 3, 4 ในเวบ
http://docs.djangoproject.com/en/1.1/intro/tutorial01/#intro-tutorial01
เสร็จแล้วผมต้องการทำการให้ Poll มีหน้าตาและความสามารถ เหมือนกับหน้า admin ตาม ลิงค์ข้างล่าง
ในรูปแรก(ท้ายสุดของ tutorial)

http://docs.djangoproject.com/en/1.2/intro/tutorial02/#intro-tutorial02

ผมต้องเขียน viwe และ Template inheritance อย่างไงครับ

chiwawa Fri, 30/07/2010 - 14:12

ผมใช้ django 1.1

http://localhost:8080/admin/polls/poll/ (port อาจไม่เหมือนกัน)
อันนี้เป็น url บนเครื่องผม ที่หน้า admin page มีหน้าตาเหมือนใน
http://docs.djangoproject.com/en/1.2/intro/tutorial02/#intro-tutorial02
ในรูปแรก(ท้ายสุดของ tutorial)

แต่ ตอนทำตัวอย่างที่ 3
http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03
ท่อนกลาง

{% if latest_poll_list %}

    {% for poll in latest_poll_list %}

  • {{ poll.question }}
  • {% endfor %}

{% else %}

No polls are available.

{% endif %}

เป็น code ใน [template_directory]/polls/index.html ตามตัวอย่าง
เวลาเข้าไปดู ก็เข้าตามนี้ครับ
http://localhost:8080/polls

สิ่งที่ได้ หน้าตาไม่เหมือนใน admin page ผมต้องการ ให้มันเหมือนหน้า admin page
และต้องการ ทั้งปุ่ม Add poll และ filter ด้านข้างเหมือนหน้า admin

ผมต้องเขียน viwe และ Template inheritance อย่างไงครับ

ต้องแยกนะครับ ระหว่าง Admin site กับ View ไม่เหมือนกันเลย

คุณสร้าง VIew ขึ้นมาเพื่อที่จะแสดง Poll แต่อยากให้เหมือนหน้า Admin ซึ่งมันเป็นไปไม่ได้
คงต้องดูจุดประสงค์ว่าจะทำไปเพื่ออะไร คุณมีทางเลือกอยู่ 2 ทาง

1.สร้าง View ขึ้นมา แล้วใช้ CSS ชุดเดียวกันกับ Admin Site แล้วจึง Import JavaScript ของ Admin Site มาใช้ สร้างหน้าเพิ่มโพล เพิ่มฟังชั่นอะไรพวกนี้ขึ้นมาเอง เพื่อให้คนนอก (ไม่จำเป็นต้องเป็นสมาชิกของเว็บ) สามารถเข้ามา Vote

  1. Cuztomize หน้า Admin Site ให้เป็นอย่างที่ต้องการ สำหรับให้สมาชิกเข้ามา Vote เท่านั้น

http://docs.djangoproject.com/en/1.1/intro/tutorial02/#intro-tutorial02
หัวข้อ Customize the admin form

class PollAdmin(admin.ModelAdmin):
fields = ['pub_date', 'question']

admin.site.register(Poll, PollAdmin)

เพียงเขียนโค้ด ง่ายๆ ก็สามารถ สร้างหน้าเวบได้อย่างรวดเร็ว ซึ่งใน
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/
หัวข้อ Templates which may be overridden per app or model
ได้พูดถึง Templates เหล่านี้

* app_index.html
* change_form.html
* change_list.html
* delete_confirmation.html
* object_history.html

มันทำให้ผมคิดว่า มีวิธีที่ จะทำหน้าเว็บได้อย่างรวดเร็ว เหมือนการสร้าง หน้า admin
ผมก็อ่าน แบบผ่านๆ ครับ ภาษาอังกฤษยังไม่ดีพอ

ถ้าผมต้องการใช้ หน้า admin โดยไม่ลอกออน เข้าไป จะมีวิธีไหนทำได้บ้างครับ

จะไป customize หน้า admin ผมว่าอาจจะยุ่งยากเกินไป ลองทำตามตัวอย่างนี้ดูก่อนดีใหมครับ Django Djumpstart: Build a To-do List in 30 Minutes พอทำไอ้นี้ได้ ไปเรื่องต่อๆไปก็ง่ายแล้ว

chiwawa Thu, 05/08/2010 - 10:42

In reply to by chiwawa

http://docs.djangoproject.com/en/1.1/ref/contrib/admin/
หัวข้อ Templates which may be overridden per app or model
ได้พูดถึง Templates เหล่านี้

  • app_index.html
  • change_form.html
  • change_list.html
  • delete_confirmation.html
  • object_history.html

ทำไว้ดีมากเลยครับ สิ่งที่ขาดไปคือ

  • detail_form.html
    ซึ่งผมคิดว่าน่าจะดียิ่งขึ้น โดยที่แสดงเหมือน * change_form.html แต่ไม่สามารถแก้ไขได้

เช่น http://localhost:8080/admin/polls/poll/ บนเครื่องผม จะไปหน้า

  • change_list.html ก่อนซึ้งมีหน้าตาเหมือน

http://docs.djangoproject.com/en/1.2/intro/tutorial02/#intro-tutorial02
ในรูปแรก(ท้ายสุดของ tutorial)

แล้วพอคลิกลิงค์ อยากให้มันไปที่ * detail_form.html โดยที่แสดงเหมือน

  • change_form.html แต่ไม่สามารถแก้ไขได้
    ข้างล่างเหมือนจะมีปุ่ม delete กับ edit จะดีมาก

ขอพูดถึง auth change group
ผมได้ตั้งค่า chosen permissions

polls | choce | Can add choice
polls | poll | Can add poll

ผลคือ ไม่สามารถไปที่ http://localhost:8080/admin/polls/poll/ เพราะไม่มีสิทธิ
จึงทำให้ผมมีแนวคิดว่า อยากให้มี * detail_form.html เกิดขึ้น แล้วเพิ่มสิทธิ
polls | poll | Can look poll หรือ
polls | poll | Can see poll

แนวคิดครับ
1 permissions ของ poll และ choce ถูกสร้างขึ้นตอนไหนครับ?? ( เดาว่า หลังคำสั่ง python manage.py syncdb)
2 จะสร้าง permissions , polls | poll | Can see poll โดยสร้างผ่าน ข้อ 1 โดยออโตเมติก
3 จะให้หน้า admin มีหน้า * detail_form.html โดยสร้างผ่าน ข้อ 1 โดยออโตเมติก

ถ้าผมอยากทำ ควรเริ่มตรงไหนดี

    • โห มีปัญหากันเต็มเลยหรอครับ ผมก็เป็นเหมือนกันครับ แต่ตอนนี้กำลัง หมกมุ่นกับ django ไม่ได้มาบอกผลเลยว่าได้ไหม ก็ยังมึนๆกับการทำ authen สมัครสมาชิก ลอกอินเหมือนเดิม !

แนะนำตัวนี้ครับ
http://bitnami.org/stack/djangostack

ติดตั้งง่าย มีให้เลือกลงได้หลาย os
ผมใช้บนวินโดว์
แต่จะได้ version 1.1 นะครับ
แล้วลองทำตาม tutorial
http://docs.djangoproject.com/en/1.1/intro/tutorial01/

ลดการปรับแต่ง ดาต้าเบสครับ
มันจะลงให้ค่อนข้าง สำเร็จรูป เหมาะแก่การเ่ริ่มต้นครับ

สำหรับการ config db(MySQL) ให้ใช้ utf8 สำหรับภาษาไทย เพื่ม

DATABASE_OPTIONS = {
"charset": "utf8",
"init_command": "SET storage_engine=InnoDB",
}

ในไฟล์ setting.py

ถ้าเคยใช้คำสั่ง python manage.py syncdb มาแล้ว
ผมไม่แน่ใจว่า จะมีผลหรือไม่

ให้ทำการ Drop table ใน db ของคุณ แล้วสร้างขึ้นมาใหม่ด้วย
python manage.py syncdb
จะทำให้ MySQL ใช้ภาษาไทยได้นะครับ

ถ้าอยากใช้ หน้า admin ภาษาไทย
เปลี่ยนจาก
LANGUAGE_CODE = 'en-us'
เป็น
LANGUAGE_CODE = 'th'

ภาษาไทยคุณก๊พร้อมใช้แล้ว

จำได้ว่ามี พี่ๆ เคยแจก เขียนDjangoใน30นาที ใครยังมีไฟล์อยู่บ้างหรือเปล่าครับ ผมอยากจะเอามาอ่านกับเื่พื่อนครับ แต่จำได้ว่าลิ้งค์เสียไปแล้ว ใครมีรบกวนช่วยแนะนำทีครับ !

อาจจะไม่ตรงคำถามซะทีเดียวนะครับ แต่เห็นมีคนพูดถึง django admin กัน เลยอยากแนะนำให้อ่านที่นี่ดูครับ และคงมีประโยชน์กับค้นตั้งกระทู้บ้าง
http://www.djangobook.com/en/2.0/chapter06/

หนังสือนี้ เขียนโดยนักพัฒนาของ django (ผมอ้างอิงตาม about the book ครับ) ขอยกมา 2 ย่อหน้านะครับ

For a certain class of Web sites, an admin interface is an essential part of the infrastructure. This is a Web-based interface, limited to trusted site administrators, that enables the adding, editing and deletion of site content. Some common examples: the interface you use to post to your blog, the backend site managers use to moderate user-generated comments, the tool your clients use to update the press releases on the Web site you built for them.

One final point we want to make clear is: the admin site is not an end-all-be-all. Over the years, we’ve seen it hacked and chopped up to serve a variety of functions it wasn’t intended to serve. It’s not intended to be a public interface to data, nor is it intended to allow for sophisticated sorting and searching of your data. As we said early in this chapter, it’s for trusted site administrators. Keeping this sweet spot in mind is the key to effective admin-site usage.

ผมไม่แน่ใจว่าเคยอ่านเจอที่ไหน แต่เหมือนจำได้ว่าการออกแบบของ Admin-Site ไม่ได้เน้นในเรื่องของ security สำหรับ public user ด้วย นะครับ ซึ่งผมก็คิดว่าตรงกับเจตนาข้างต้นที่เค้าเขียนไว้ครับ

สำหรับประสบการณ์ส่วนตัวแล้ว ถ้าตั้งใจจะใช้ django จริงๆ ในระยะยาว (ในระยะเริ่มต้นไม่เป็นไรนะครับ อยากทำอะไรก็ลองทำไปเลย แต่แนะนำไว้นิดนึง ^^ ไว้ไปดูเมื่อถึงเวลาครับ) (รวมถึง open source framework ตัวอื่นๆ ด้วย) ผมแนะนำให้อ่านจาก community ของเค้าเองจะดีที่สุดครับ ต้องเข้าใจนิดนึงว่า การใช้ framework สามารถทำให้เราทำงานได้เร็วขึ้น แต่ก็จำเป็นที่จะต้องทราบถึงทิศทางการพัฒนาโปรแกรม เพื่อที่เราจะได้วางแผนและออกแบบโปรแกรมให้สอดคล้องด้วยครับ เนื่องจากเค้าจะมีการ update อยู่เรื่อยๆ บาง features, settings ก็มีการเปลี่ยนแปลง แต่ผมว่า ยังไงก็คุ้มกว่าเราทำเองเยอะครับ ^^

อ่อตรงหมวดหัวข้อที่โพสผมทำเสร็จแล้วครับแค่อยากจะสอบถามถึง ที่พี่ๆ เขาเคยทำ django ภาษาไทยภายใย สามสิบนาที หนะครับแต่เห็นลิ้งค์เก่าหมดอายุเลยอยากจะขอเก็บไว้หนะครับ แต่คงไม่เป็นไรครับ

ผมติดปัญหา ตรงการลอกอิน การสมัครสมาชิก มันไม่ได้ผ่านครับมันขึ้นว่า

Help

Reason given for failure:

CSRF token missing or incorrect.

In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

The view function uses RequestContext for the template, instead of Context.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.