国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

flask bootstrap頁面json格式化

這篇具有很好參考價(jià)值的文章主要介紹了flask bootstrap頁面json格式化。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

flask bootstrap頁面json格式化,# Flask,# html,flask,python,后端文章來源地址http://www.zghlxwxcb.cn/news/detail-733592.html

html

<!DOCTYPE html>
<html lang="en">
<head>

<!-- 新 Bootstrap5 核心 CSS 文件 -->
<link rel="stylesheet" href="static/bootstrap-5.0.0-beta1-dist/css/bootstrap.min.css">

<!-- 最新的 Bootstrap5 核心 JavaScript 文件 -->
<script src="static/bootstrap-5.0.0-beta1-dist/js/bootstrap.bundle.min.js"></script>

    <script>
        function submitForm() {
            document.getElementById('myForm').submit();
        }

        function clearTextarea() {
            var textarea = document.getElementById('myTextarea');
            textarea.value = '';  // 清空 textarea 的內(nèi)容
        }
    </script>



  <meta charset="UTF-8">
    <title>Title</title>

  <style>
    .form-control.input-lg {
      height: 500px;
    }
  </style>




</head>
<body>



<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-dark bg-dark bg-dark">
  <div class="container-fluid">

    <a class="navbar-brand" href="#">
      <img src="static/glyph-iconset-master/svg/si-glyph-desktop.svg" alt="" width="30" height="30" class="d-inline-block align-top">
      工具大全
    </a>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarNavDropdown">

      <ul class="navbar-nav">

        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">首頁</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="#">test1</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="#">test2</a>
        </li>


        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            test3
          </a>

          <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <li><a class="dropdown-item" href="#">1</a></li>
            <li><a class="dropdown-item" href="#">2</a></li>
            <li><a class="dropdown-item" href="#">3</a></li>
          </ul>
        </li>


      </ul>



    </div>



<!--            <ul class="nav justify-content-end">-->
<!--        <li class="nav-item">-->
<!--          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>-->
<!--          -->
<!--        </li>-->
<!--      </ul>-->


<div class="dropdown dropdown-menu-end">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">
  登出
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">首頁</a></li>
    <li><a class="dropdown-item" href="#">注銷</a></li>
  </ul>
</div>




  </div>
</nav>



<!--容器-->
<div class="container">

<!--  按鈕-->

  <div class="d-grid gap-2 d-md-block " >

    <button onclick="submitForm()" class="btn btn-primary" type="button" type="Submit">格式化</button>
    <button onclick="clearTextarea()" class="btn btn-primary" type="button">清空輸出框內(nèi)容</button>

  </div>

<h2>JSON 格式化工具</h2>



  <div class="row align-items-start">
<!--    文本框-->
    <div class="col-6">
      <h5>輸入</h5>

    <form  id="myForm" method="POST">
     <textarea class="form-control" id="deblock_udid" name="textarea_name" rows="30" style="min-width: 50%">{{ textarea_content }}</textarea>
    </form>

    </div>
  <!--    文本框-->
    <div class="col-6">
      <h5>輸出</h5>
      <textarea class="form-control" id="myTextarea" name="deblock_udid" rows="30" style="min-width: 50%">{{ processed_data }}</textarea>
    </div>


  </div>
</div>

<div class="container">
  <div class="alert alert-light" role="alert">
      {% if error_message %}
        <p style="color: red;">Error: {{ error_message }}</p>
    {% endif %}
</div>

</div>






</body>
</html>

app.py

from flask import Flask, render_template, request
import json

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        textarea_content = request.form.get('textarea_name')  # 獲取提交的 textarea 內(nèi)容

        print(textarea_content)

        parsed_data = None
        error_message = None
        if textarea_content:
            try:
                parsed_data = json.loads(textarea_content)
            except json.decoder.JSONDecodeError as e:
                # 處理非法的 JSON 字符串
                error_message = str('格式非法')

        # 格式化輸出 JSON 數(shù)據(jù)
        formatted_data = json.dumps(parsed_data, indent=4, ensure_ascii=False) if parsed_data else ''

        return render_template('student.html', textarea_content=textarea_content, processed_data=formatted_data,
                               error_message=error_message)  # 將內(nèi)容和錯(cuò)誤信息傳遞回前端頁面
    else:
        return render_template('student.html')


if __name__ == '__main__':
    app.run()

到了這里,關(guān)于flask bootstrap頁面json格式化的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Python(21)json.dumps()使用indent參數(shù) 格式化輸出json數(shù)據(jù)格式

    json.dumps() 方法 將一個(gè)Python數(shù)據(jù)結(jié)構(gòu)轉(zhuǎn)換為JSON字符串 輸出為 這樣的格式一般都不優(yōu)美,當(dāng)數(shù)據(jù)很多的時(shí)候,看得就不是很直觀方便。 可以使用 indent=4 參數(shù)來對json進(jìn)行數(shù)據(jù)格式化輸出,會(huì)根據(jù)數(shù)據(jù)格式縮進(jìn)顯示,讀起來更加清晰 用法如下 輸出為 json.dumps()方法,參數(shù)解釋

    2024年02月08日
    瀏覽(26)
  • js將數(shù)組變量json格式化

    在js中,js變量和JSON是兩個(gè)不同數(shù)據(jù)格式,兩者的儲(chǔ)存方式自然不相同。JSON格式是一種數(shù)據(jù)交換的規(guī)則,js變量則是javascript在程序需求場景中的數(shù)據(jù)表示。在js與不同語言的服務(wù)端進(jìn)行數(shù)據(jù)交換過程中,js能夠有內(nèi)置的方法將其變量轉(zhuǎn)化為JSON格式。 但是對于JS數(shù)組而言,如果

    2024年02月08日
    瀏覽(26)
  • Java json 格式化小工具兼容轉(zhuǎn)義 json 串

    封裝了一個(gè)格式化 json 小工具,支持標(biāo)準(zhǔn)的 json 格式 和 經(jīng)過后端編程語言如 java 轉(zhuǎn)義后的 字符串 json 格式的格式化輸出,代碼如下: 我們看下兩種 json 數(shù)據(jù): 注意第一種使用 JSON 工具處理時(shí),并不能正常解析,需要先轉(zhuǎn)義才行,注意: 在 IDEA中 測試時(shí)不能直接將上面的內(nèi)

    2024年02月07日
    瀏覽(17)
  • json格式化BigDecimal,保留2位小數(shù)

    json格式化BigDecimal,保留2位小數(shù)

    如下,在處理錢相關(guān)的業(yè)務(wù)時(shí),接口明明已經(jīng)保留了兩位小數(shù) 1.00 ,但前端接收的時(shí)候獲取的卻是 1 ,小數(shù)點(diǎn)后面的‘0’沒了。 其實(shí), 需要在 BigDecimal 參與 json 轉(zhuǎn)化時(shí),將其轉(zhuǎn)化成 String 類型即可 。 1.編寫一個(gè)類,實(shí)現(xiàn) JsonSerializer ,并實(shí)現(xiàn) serialize 方法 2.在需要特殊處理的

    2024年02月08日
    瀏覽(17)
  • HTML標(biāo)題、段落、文本格式化

    HTML標(biāo)題、段落、文本格式化

    HTML標(biāo)題: 在HTML文檔中,標(biāo)題是很重要的。標(biāo)題是通過h1 - h6標(biāo)簽進(jìn)行定義的,h1 定義最大的標(biāo)題;h6定義最小的標(biāo)題。 hr 標(biāo)簽在HTML頁面中用于創(chuàng)建水平線,hr元素可用于分隔內(nèi)容。 可以將注釋插入到HTML代碼中,可以提高代碼可讀性。注釋的寫法如下:!-- 這是注釋 --。 body定

    2024年02月06日
    瀏覽(24)
  • vue中json格式化顯示(vue-json-viewer)

    vue中json格式化顯示(vue-json-viewer)

    使用npm: 使用yarm: 使用pnpm也可以 在 main.ts 中注冊插件 在界面中使用 注意 :在main.ts文件中可能會(huì)出現(xiàn)以下得ts類型報(bào)錯(cuò): 無法找到模塊“vue-json-viewer”的聲明文件。 解決方法: 先嘗試安裝 npm i --save-dev @types/vue-json-viewer 如果上面方法不行,在全局的 .d.ts 結(jié)尾的文件中添

    2024年03月13日
    瀏覽(21)
  • Excel將單元格中的json本文格式化

    打開Excel文件并按下ALT + F11打開Visual Basic for Applications(VBA)編輯器。 輸入下面的代碼 進(jìn)入https://github.com/VBA-tools/VBA-JSON,下載release的最新代碼 VBA編輯器,“文件”-“導(dǎo)入”, 導(dǎo)入文件 JsonConverter.bas 點(diǎn)擊VBA編輯器的菜單欄上的\\\"工具\(yùn)\\"。 選擇\\\"引用\\\",然后在彈出的對話框中找到

    2024年02月14日
    瀏覽(28)
  • UE編輯器格式化xml或json

    UE編輯器格式化xml或json

    UE編輯器格式化XML數(shù)據(jù),首先菜單【視圖】=》【查看方式】=》【XML】,然后選中需要進(jìn)行格式化的內(nèi)容,點(diǎn)擊菜單【格式】=》【重新縮進(jìn)選擇】 ?UE編輯器格式化JSON數(shù)據(jù),首先菜單【視圖】=》【查看方式】=》【JSON】,然后選中需要進(jìn)行格式化的內(nèi)容,點(diǎn)擊菜單【格式】=》

    2024年02月11日
    瀏覽(25)
  • Java工具類——json字符串格式化處理

    Java工具類——json字符串格式化處理

    在我們拿到一團(tuán)未經(jīng)格式化的json字符串時(shí),非常不方便查看,比如這樣 因此隨手寫了個(gè)工具類用來格式化json。注意,原json字符串必須語法無誤,并且不包含換行、空格、縮進(jìn)等,否則會(huì)保留下來。 ok廢話不多說上代碼 運(yùn)行后效果

    2024年01月17日
    瀏覽(29)
  • sublime text 格式化json快捷鍵配置

    sublime text 格式化json快捷鍵配置

    以 control+command+j 為例。 打開Sublime Text,依次點(diǎn)擊左上角菜單Sublime Text-Preferences-Key Bindings,出現(xiàn)以下文件: 左邊的是Sublime Text默認(rèn)的快捷鍵,不可編輯。右邊是我們自定義快捷鍵的地方,在中括號(hào)中加入以下數(shù)據(jù)并保存:

    2024年02月10日
    瀏覽(13)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包