在url Django中发送列表(UNICODE)

时间:2021-11-05 18:05:58

i want to sent the result of a database query in the url. The problem is that i can't find a url that matches the result.

我想在网址中发送数据库查询的结果。问题是我找不到与结果匹配的网址。

i made a function that removes the ( ) characters in the result. But at the moment of send it, i get this error.

我创建了一个删除结果中的()字符的函数。但在发送它的那一刻,我得到了这个错误。

Reverse for 'deleteProject' with arguments '(u'Juegos',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['Administration/deleteProject/(?P[-\d]+)$']

使用参数'(u'Juegos',)'和关键字参数'{}'找不到'deleteProject'的反转。尝试了1种模式:['Administration / deleteProject /(?P [ - \ d] +)$']

views.py

def index(request):
    arrayBases = getDatabases(request)
    return render(request, 'index.html', {
        'arrayBases': arrayBases,
    })

def getDatabases(request):
    cursor= connection.cursor()
    cursor.execute("SELECT * FROM Administration_proyecto")
    bases = cursor.fetchall()
    arrayBases = []
    for i in bases:
        for j in i:
            arrayBases.append(j)
    return arrayBases

def deleteProject(request, base):
    print request
    return HttpResponseRedirect(reverse('index'))

index.html

<table>

  <tr>
  <th>Nombre del proyecto</th>
  <th>Acción</th>
</tr>

{% if arrayBases %}
  {% for base in arrayBases %}
  <tr>
    <td id="{{ base }}"> {{ base }} </td>
    <td>
      <a href="{% url 'deleteProject' base %}">
        <img height="15px" src="{% static "icons/delete.svg" %}">
      </a>
    </td>

  </tr>
  {% endfor %}
{% endif %}

</table>

urls.py

urlpatterns = [
    url(r'^index/$', views.index, name='index'),
    url(r'^deleteProject/(?P<base>[-\d]+)$', views.deleteProject, name="deleteProject"),
]

i tried changing the d for a w in the url, but it doesn't works

我尝试在网址中更改d为w,但它不起作用

1 个解决方案

#1


0  

You can change your URL endpoint regular expression pattern to:

您可以将URL端点正则表达式模式更改为:

^deleteProject/(\w+)/?$

where (\w+) is a non-named capturing group that would match one or more alphanumeric characters.

其中(\ w +)是一个与一个或多个字母数字字符匹配的非命名捕获组。

#1


0  

You can change your URL endpoint regular expression pattern to:

您可以将URL端点正则表达式模式更改为:

^deleteProject/(\w+)/?$

where (\w+) is a non-named capturing group that would match one or more alphanumeric characters.

其中(\ w +)是一个与一个或多个字母数字字符匹配的非命名捕获组。