0

I am trying to build a simple search function on django that leads me to the link when I click on it. (I know API links are JSON links so clicking on them gives you no output of value but the point is to be able to click on them)

i tried using but it doesn't work

from my results.html:

{% for dataset in datasets %}
<br/>
{{ dataset.datasets_available }}
<br/>
{{ dataset.data_source }}
<br/>
{{ dataset.brief_description_of_datasets }}
<br/>
{{ dataset.country }}
<br/>
<a href='https://www.google.com'>{{ dataset.api_documentation }}<a>
<br/> #^ is the part i wanna fix
<br/>
{% endfor %}
{% else %}
<p style="font-family:Cambria">No search results for this query</p> 
{% endif %}`

from views.py:

def results(request):
query = request.GET.get('q')
if query:
    datasets = api_data.objects.filter(Q(datasets_available__icontains=query))
    context = {
        'datasets': datasets,
    }
return render(request, 'Search/results.html', context)

from models.py:

class api_data(models.Model):
data_source = models.TextField()
brief_description_of_data = models.TextField()
datasets_available = models.TextField()
brief_description_of_datasets = models.TextField()
country = models.TextField()
api_documentation = models.TextField()

class Meta:
    verbose_name_plural = "api_data"

api_documentation is currently urls in strings. i want to be able to click on the output in html and view the actual website

1 Answer 1

1

I'm not sure what you're trying to do, but if the website URL is in the api_documentation field, then you need to make this field the href of your html anchor.

Something like this:

<a href='{{ dataset.api_documentation }}'>{{ dataset.api_documentation }}</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.