简体   繁体   English

Django-将价值从一种观点转移到另一种观点

[英]Django - put value from one view to another

This is a part of my template file: 这是我的模板文件的一部分:

{% for tag, value in tags.items %}
    <a style="color: {{value.1}}; font-size: {{value.2}}px " href="{% url 'tags' tag|slugify  %}">{{ tag }}</a> ({{value.0}}),
{% endfor %}

Url looks like: http://127.0.0.1:8000/tag/my-simple-url/ 网址看起来像: http : //127.0.0.1 : 8000/tag/my-simple- url/

I need to get "my-simple-url" as my "simple url" in my next view. 我需要在下一个视图中将“ my-simple-url”作为我的“ simple url”。 Now it looks like: 现在看起来像:

def tags(request, slug):
    context = {}
    tags = Tags().tag_filer_sites(slug.replace('-', ' '))
    context['slug'] = slug
    context['tags'] = tags['sites']
    return render(request, 'mainapp/all_tags.html', context)

but I have to use full name instead of slug. 但我必须使用全名而不是。 How can I achieve that? 我该如何实现? I need to find a way to put tag into url or get it in different way but I don't know how can I do this. 我需要找到一种方法将标记放入url或以其他方式获取它,但我不知道该怎么做。

Try something like this 试试这个

def tags(request, slug):
    context = {}
    tags = Tags().tag_filer_sites(slug.replace('-', ' '))

    context['slug'] = slug
    context['full_name'] = Tag.objects.filter(slug=slug)
    context['tags'] = tags['sites']

    return render(request, 'mainapp/all_tags.html', context)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM