weixin_33739541 2014-08-04 13:38 采纳率: 0%
浏览 20

Django表单无法验证

I have been spending multiple days trying to get to the bottom of this problem but I still haven't figured it out.

I'm working on a website that allows people to share or rent musical instruments to peers near them. One of the pages is "Offer Instrument", and on this page there is a form. The form has two main purposes; to allow you to search for someone near you looking for this instrument, or to post your listing to the site.

If you click "Search", the site only looks at two pieces of data, the type of instrument and the location. If you click "Post", the site looks at all the input boxes (i.e. size, age, brand, etc), and enters it in.

When you click "Search", an Ajax request is sent to the view instrument_offering_search(request) where it is supposed to processed and results are supposed to be returned. However the form object is never returning valid.

def instrument_offer_search(request):    
    if request.method == 'POST':
        form = InstrumentOfferSearchForm(request.POST)
        if form.is_valid():
             #always returning false
        else: 
             .....

When you click "Post", an Ajax request is sent to the view instrument_offering(request) where it is processed and added to the database. This works fine

def instrument_offering(request): 
    if request.method == 'POST':
        form = InstrumentOfferForm(request.POST)
        if form.is_valid():
             #works!

I've verified by using both Chrome tools and pdb that the Search button is definitely sending the POST data.

Why isn't the form being valid?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度