如何在脚本中将函数参数传递给url_for

时间:2019-01-23 04:28:23

标签: javascript python flask

我正在尝试将参数传递给脚本中的function oceanwp_child_enqueue_parent_style() { $theme = wp_get_theme( 'OceanWP' ); $version = $theme->get( 'Version' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css',array( 'oceanwp-style' ), $version ); } // ADD THIS add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style'); function my_theme_enqueue_styles() { $parent_style = 'oceanwp-style'; if ( is_front_page() ) { wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' , '/style-rtl.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/front-page-style.css', array( $parent_style ), wp_get_theme('')->get('Version') ); }else{ wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' , '/style-rtl.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme('')->get('Version')); } } // UPDATE THIS add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles');

在我的html代码上。

url_for

还有我的脚本代码。

<div class="float-right">
    <a href="#" onclick="view_article('aaa')">click</a>
</div>

还有我的python代码。

function view_article(id){
    var w=700, h=1200, l=(screen.availWidth - w) / 2, t=(screen.availHeight - h) / 2;
    window.open("{{ url_for('articles.article_detail', articleId="+id+") }}","_blank","width= "+ w + ",height=" + h + ",left=" + l + ",top=" + t + ", scrollbars = yes, location = no, toolbar = no, menubar = no, status = no");
    };

我希望返回@articles.route("/article/detail/<articleId>", methods=['GET', 'POST']) def article_detail(articleId): return articleId

但是在此代码中,它返回aaa

我尝试使用+id+代替articleId=id

但这也不起作用...

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您可以使用伪造的商品ID并将其替换为真实ID:

def self.search(search)
    if search
        where('name_of_organisation LIKE ?', "%#{search}%")
    else
        all
    end
end


filterrific(
available_filters: [
        :search_query           
 ]
)

 scope :search_query, lambda { |query|
    return nil  if query.blank?

    terms = query.downcase.split(/\s+/)

    terms = terms.map { |e|
        (e.gsub('*', '%') + '%').gsub(/%+/, '%')
    }

    num_or_conds = 1
     where(
        terms.map { |term|
            "(LOWER(organisations.name_of_organisation) LIKE ?) 
        }.join(' AND '),
        *terms.map { |e| [e] * num_or_conds }.flatten
    )
}
相关问题