小编Iz *_*z M的帖子

Flask:重定向不存在的URL

我被告知要执行以下操作:修改app.py文件,以便我的网站响应所有可能的URL(也就是不存在的扩展名,如'/ jobs',这意味着如果输入的URL无效,则会重定向到home索引.html页面.这是我的app.py的副本,有关如何执行此操作的任何想法?

from flask import Flask, render_template  #NEW IMPORT!!

app = Flask(__name__)    #This is creating a new Flask object

#decorator that links...

@app.route('/')                                 #This is the main URL
def index():
    return render_template("index.html", title="Welcome",name="home")       

@app.route('/photo')
def photo():
    return render_template("photo.html", title="Home", name="photo-home")

@app.route('/about')
def photoAbout():
    return render_template("photo/about.html", title="About", name="about")

@app.route('/contact')
def photoContact():
    return render_template("photo/contact.html", title="Contact", name="contact")

@app.route('/resume')
def photoResume():
    return render_template("photo/resume.html", title="Resume", name="resume")

if __name__ == '__main__':
    app.run(debug=True)     #debug=True is optional
Run Code Online (Sandbox Code Playgroud)

python flask web

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

在sql中选择将表与自身连接的不同对

我有一个包含两行的表:IMDB_ID 和 Actor。我试图找到在 3 部或更多电影中共同主演的演员对。这对名称应该是唯一的,这意味着“演员 A,演员 B”和“演员 B,演员 A”是同一对,因此应该只出现其中一个。这是表格的几行,但不是全部:

IMDB_ID     ACTOR      
----------  -----------
tt0111161   Tim Robbins
tt0111161   Morgan Free
tt0111161   Bob Gunton 
tt0111161   William Sad
tt0111161   Clancy Brow
tt0111161   Gil Bellows
tt0111161   Mark Rolsto
tt0111161   James Whitm
tt0111161   Jeffrey DeM
tt0111161   Larry Brand
tt0111161   Neil Giunto
tt0111161   Brian Libby
tt0111161   David Prova
tt0111161   Joseph Ragn
tt0111161   Jude Ciccol
tt0068646   Marlon Bran
tt0068646   Al Pacino  
Run Code Online (Sandbox Code Playgroud)

我试过:

SELECT DISTINCT movie_actor.actor, movie_actor.actor, COUNT(movie_actor.actor) AS occurrence 
   FROM movie_actor join movie_actor 
   ON movie_actor.imdb_id = movies.imdb_id …
Run Code Online (Sandbox Code Playgroud)

sql sqlite join distinct

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

从Spark中的数据框列值中删除空格

我有一个business_df架构的数据框():

|-- business_id: string (nullable = true)
|-- categories: array (nullable = true)
|    |-- element: string (containsNull = true)
|-- city: string (nullable = true)
|-- full_address: string (nullable = true)
|-- hours: struct (nullable = true)
|-- name: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)

我想创建一个新的数据框(new_df),以便'name'列中的值不包含任何空格.

我的代码是:

from pyspark import SparkContext
from pyspark.sql import SQLContext
from pyspark.sql import HiveContext
from pyspark.sql.functions import UserDefinedFunction
from pyspark.sql.types import StringType

udf = UserDefinedFunction(lambda x: x.replace(' ', ''), StringType()) …
Run Code Online (Sandbox Code Playgroud)

python dataframe apache-spark apache-spark-sql

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

标签 统计

python ×2

apache-spark ×1

apache-spark-sql ×1

dataframe ×1

distinct ×1

flask ×1

join ×1

sql ×1

sqlite ×1

web ×1