使用pythonDjango restfulapi

2024-10-01 17:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

需要帮助

我为我的应用程序编写了一个flutter小部件,供用户在我的应用程序中注册,还编写了一个带有Django restfulapi的API。如何将pythondjango中的API路由/URL与flutter小部件连接或集成?拜托,我需要一个样本代码。我会很感激你的帮助。在

这是我的注册flutter widget:

  import 'package:flutter/material.dart';

    class SignUpPage2 extends StatefulWidget {
      @override
     SignUpPage2State createState() => SignUpPage2State();
    }

    class SignUpPage2State extends State<SignUpPage2> { 

    @override
      Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,

        leading:  IconButton(
                  icon: new Icon(Icons.arrow_back, 
                  color:Colors.orange.shade700),
                        onPressed: () { 

                          Navigator.pop(context);

                           },
                    ),

        title: Text("Create acount", style: TextStyle(color:Colors.orange.shade700)),
        backgroundColor: Colors.black,
      ),
      backgroundColor: Colors.black45,
      body: Center(
        child: ListView(
          shrinkWrap: true,
          padding: EdgeInsets.only(left: 24.0, right: 24.0),
          children: <Widget>[

              new Center(
                child: new Text("Welcome",
                style: new TextStyle(
                  color: Colors.orange.shade700,
                  fontFamily: 'Poppins-Bold',
                  fontSize: 30.0,
                ),
                textAlign: TextAlign.center,
                ),   
            ), 
            SizedBox(height: 10.0),

            new Center(
                child: new Text("Please, Introduce Yourself",
                style: new TextStyle(
                  color: Colors.white,
                  fontFamily: 'Poppins',
                  fontSize: 20.0,
                ),
                textAlign: TextAlign.center,
                ),   
              ),  
            SizedBox(height: 20.0),

            TextField(
                keyboardType: TextInputType.text,
                autofocus: false,
                decoration: InputDecoration(
                  hintText: 'First Name',
                  filled: true,
                  fillColor: Colors.white,
                  contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(32.0),
                  ),
                ),
              ),
              SizedBox(height: 15.0),


              TextField(
                  keyboardType: TextInputType.text,
                  autofocus: false,
                  decoration: InputDecoration(
                    hintText: 'Last Name',
                    filled: true,
                    fillColor: Colors.white,
                    contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(32.0),
                    ),
                  ),
                ),
              SizedBox(height: 15.0),

              TextField(
                  keyboardType: TextInputType.phone,
                  autofocus: false,
                  decoration: InputDecoration(
                    hintText: 'Phone',
                    filled: true,
                    fillColor: Colors.white,
                    contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(32.0),
                    ),
                  ),
                ),
              SizedBox(height: 15.0),


               TextField(
                  keyboardType: TextInputType.datetime,
                  autofocus: false,

                  decoration: InputDecoration(
                    hintText: 'Date of Birth',
                    filled: true,
                    fillColor: Colors.white,
                    contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(32.0),
                    ),
                  ),
                ),
              SizedBox(height: 15.0),

              TextField(
                    keyboardType: TextInputType.text,
                    autofocus: false,
                    obscureText: true,
                    // initialValue: 'john@gmail.com',
                    decoration: InputDecoration(
                      hintText: 'Password',
                      filled: true,
                      fillColor: Colors.white,
                      contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(32.0),
                      ),
                    ),
                  ),
              SizedBox(height: 15.0),

              Padding(
                      padding: EdgeInsets.symmetric(
                        vertical: 16.0),
                        child: Material(
                          borderRadius: BorderRadius.circular(30.0),
                          // shadowColor: Colors.orange.shade700,
                          // elevation: 5.0,
                          child: MaterialButton(
                              minWidth: 200.0,
                              height: 60.0,
                              onPressed: (){
                                setState(() {

                                Navigator.of(context).pushNamed('/SignUpPage3');


                              } ,
                              color: Colors.orange.shade700,
                              child: Text(
                                "Next", 
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 23.0,
                                  ),
                              ),
                          ),
                        ),
                    ),

          ]
        ),
      ),
    );
  }}

Tags: childtruenewcolortextfieldwhitecolorsheight
1条回答
网友
1楼 · 发布于 2024-10-01 17:35:28

您需要将http包添加到项目中。然后将对Python REST端点的http调用包装在Future中。 我不喜欢发布链接作为答案,但在这种情况下,没有什么比这个Cookbookexample更好的答案了你的问题!在

相关问题 更多 >

    热门问题