小编Ste*_*e77的帖子

Flask Python,试图返回列表或dict到Ajax调用

在Flask应用程序中,我有以下ajax调用:

    $.ajax({
            url: "{{ url_for( 'bookings.get_customer' ) }}",
            type: "POST",
            data: nameArray,
            success: function( resp ){
                console.log( resp )
            }
        })
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我正在传递一个数组,我将搜索我的mongo数据库,它将返回或不返回客户.

所以,负责处理这个ajax调用的python def是:

@bookings.route( '/get_customer', methods=[ 'POST' ] )
def get_customer():
    name = {}
    for key, value in request.form.items():
     name[ key ] = value

    customer_obj = customer_class.Customer()
    results = customer_obj.search_customer( name )

    return results    
Run Code Online (Sandbox Code Playgroud)

为了论证,让我们说customer_obj调用返回以下列表:

[{'customer': {
               u'first_name': u'Dave', 
               u'tel': u'0121212121458', 
               u'country': u'UK',     
               u'address2': u'Townington', 
               u'address3': u'Cityville', 
               u'email': u'dave@smith.com', 
               u'postcode': u'A10 5BC', 
               u'address1': u'10 High Street', 
               u'second_name': u'Smith'
             }, …
Run Code Online (Sandbox Code Playgroud)

python ajax flask

23
推荐指数
3
解决办法
4万
查看次数

Android - 在我的布局xml中错误地夸大了SimonVT NumberPicker类

我已经在这几天了,而且我已经放弃了,所以任何帮助都非常感谢!

我一直在尝试在我的Android应用程序中实现simonVT数字选择器.对于android来说是全新的,所以包括库,引用这个库并获得编译的所有东西本身就是几天的任务.现在我终于编译了所有内容我在运行时遇到以下错误:

04-06 10:58:37.126: E/AndroidRuntime(14324): java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.example.goalminder/com.example.goalminder.AddGoal}:
android.view.InflateException: Binary XML file line #81: 
Error inflating class net.simonvt.numberpicker.NumberPicker
Run Code Online (Sandbox Code Playgroud)

这是我的布局的开头:

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/net.simonvt.numberpicker"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
Run Code Online (Sandbox Code Playgroud)

注意 - 上面的'xmlns:app'部分有一个黄色警告标记 - 它没有被使用.我包含了另一个stackoverflow的答案.类似的问题.留下来劝阻这个建议.

这是numberpicker的xml:

<net.simonvt.numberpicker.NumberPicker          
    android:id="@+id/dayPicker"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="10dp"
    android:layout_weight="1"/>
Run Code Online (Sandbox Code Playgroud)

我已经在我的主题文件中按照Simon的指示包含了主题.我不确定要给它的名字,所以我称它为'NumberPicker':

<resources>

    <!-- Copy one of these attributes to your own theme (choose either dark or light).
        <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
       <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
    -->
    <style name="NumberPicker" parent="android:Theme">
        <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
    </style>

    <style name="NumberPicker" parent="android:Theme.Light">
        <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

我还将以下内容添加到我的android清单中作为应用程序的子代: …

android numberpicker

8
推荐指数
1
解决办法
4345
查看次数

Python sqlite3查询在终端中工作,但不在应用程序中

已经看过这些类似的问题,但没有任何乐趣:

PHP MySQL查询不起作用,但从终端 Sqlite更新工作不正常 - python

我正在使用带有SQLite的Flask并具有以下查询:

g.db.execute( "UPDATE article_views SET views=views+1 WHERE id=:id" , { "id": this_id } )
Run Code Online (Sandbox Code Playgroud)

其中this_id是一个整数.执行没有错误.但是当我检查我的数据库时,没有发生预期的更新.

这里有人有任何见解吗?

python sqlite flask

1
推荐指数
1
解决办法
272
查看次数

标签 统计

flask ×2

python ×2

ajax ×1

android ×1

numberpicker ×1

sqlite ×1