为什么此查询返回空?

时间:2016-02-18 12:57:28

标签: python flask neo4j py2neo

我有一个使用py2neo显示组的烧瓶应用程序。我试图让网址更漂亮,所以我发现了这两篇文章:一篇关于how to generate slugs,另一篇关于how to create custom converters。我将这些文章结合起来制作了以下代码:

<% request.setAttribute("title", "Summary"); %>

# app/views.py

from flask import Flask, redirect, render_template, url_for
from models import graph, Group

app = Flask(__name__)

from .util import SlugConverter
app.url_map.converters['slug'] = SlugConverter

...

@app.route('/group/<slug:group_name>')
def show_group(group_name):

    query = """
    MATCH (group:Group)
    WHERE group.slug = {group_name}
    RETURN group
    """
    group = graph.cypher.execute_one(query, group_name = group_name)
    if group:
        return render_template('group.html', group = group)
    else:
        return redirect(url_for('show_groups'))

创建slug并替换url没有问题。我遇到的问题是,如果我通过# app/util.py from werkzeug.routing import BaseConverter import re import translitcodec class SlugConverter(BaseConverter): def to_python(self, value): pass def to_url(self, value): exp = r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+' punct_re = re.compile(exp) delim = u'_' result = [] for word in punct_re.split(value.lower()): word = word.encode('translit/long') if word: result.append(word) return unicode(delim.join(result)) query,它会返回graph.cypher.execute_one()。我不懂为什么。如果我在NEO4J Web查看器中使用相同的查询,仅替换None作为示例{group_name},则返回相关节点。

为什么此查询返回空?

1 个答案:

答案 0 :(得分:1)

$.preloadImages = function() { for (var i = 0; i < arguments.length; i++) { $("<img />").attr("src", arguments[i]); } } $.preloadImages("hoverimage1.jpg","hoverimage2.jpg"); 方法必须返回您要在视图中使用的实际值。您可以将SlugConverter.to_python值切换为to_url。只需让to_pythonto_url