内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>How do I connect my pre-exisiting html-css webpages to a python code using Flask? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I connect my pre-exisiting html-css webpages to a python code using Flask? - Stack Overflow

programmeradmin0浏览0评论

So I had been working on a code for a movie-recommendation site for a school project, which we were supposed to do in Python. It stores a dictionary of movies and takes couple inputs to recommend movies/add new movies etc. I thought of going the extra mile and I designed a html-css website for my code that has a few interlinked pages. The issue is that I can't figure out how to connect my python code to the webpages.

I haven't used web frameworks like Flask before so I can't figure out how to link it to my index.html file. Also, I don't totally get how app routes work.

I tried putting in the file path to my html file in the app route () argument but it resulted in an error. And when I put in my html code in the return value, it didn't gi ve me my designed webpage.

@app.route("/") 
def index(): 
    return "Hello World!"
  1. What does the url in the () exactly do?
  2. what argument do I pass in the def ()? and what does def actually define?
  3. How do I integrate my pre-existing python code?
  4. Where do I put in my html-css code?

So I had been working on a code for a movie-recommendation site for a school project, which we were supposed to do in Python. It stores a dictionary of movies and takes couple inputs to recommend movies/add new movies etc. I thought of going the extra mile and I designed a html-css website for my code that has a few interlinked pages. The issue is that I can't figure out how to connect my python code to the webpages.

I haven't used web frameworks like Flask before so I can't figure out how to link it to my index.html file. Also, I don't totally get how app routes work.

I tried putting in the file path to my html file in the app route () argument but it resulted in an error. And when I put in my html code in the return value, it didn't gi ve me my designed webpage.

@app.route("/") 
def index(): 
    return "Hello World!"
  1. What does the url in the () exactly do?
  2. what argument do I pass in the def ()? and what does def actually define?
  3. How do I integrate my pre-existing python code?
  4. Where do I put in my html-css code?
Share Improve this question asked Feb 2 at 2:37 fatima_r24fatima_r24 1892 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

"Put your HTML and CSS code into the same directory and use render_template from Flask to serve your HTML files."

your_project/
├── app.py
├── templates/
│   ├── index.html
└── static/
    └── style.css

"If you want to pass any argument into the function, first you need to set the route."

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/index/<movies>', methods=['GET'])
def index(movies):
    return render_template('index.html', movies=movies)

if __name__ == '__main__':
    app.run(debug=True)
发布评论

评论列表(0)

  1. 暂无评论