access league by league-code REST api

54 views
Skip to first unread message

omar ahmed

unread,
Jul 4, 2019, 5:42:05 PM7/4/19
to Django users
hiii ..
i use REST api to get data from "https://www.football-data.org" ..
i want to create one view that can restore any league (by league code like: PL for premier league) not for particular league
openleague.html
{% block content %}
<ul>
<li><a href="{% url 'core:openleague' PL %}">Premier League</a></li>
<li><a href="{% url 'core:openleague' PD %}">Spanish League</a></li>
<li><a href="{% url 'core:openleague' SA %}">Italian League</a></li>
<li><a href="{% url 'core:openleague' BL1 %}">German League</a></li>
<li><a href="{% url 'core:openleague' FL1 %}">French League</a></li>
</ul>
{% endblock %}
urls.py
urlpatterns =[
path('', views.home,name='home'),
path('<str:code>/League', views.openleague, name='openleague'),
]
views.py
def openleague(request,code):
connection = http.client.HTTPConnection('api.football-data.org')
headers = { 'X-Auth-Token': '##################' }
connection.request('GET', '/v2/competitions/{'code'}', None, headers)
response = json.loads(connection.getresponse().read().decode())

return render(request, 'core/openleague.html', {'response': response})
Message has been deleted

omar ahmed

unread,
Jul 5, 2019, 1:31:08 PM7/5/19
to Django users
please explain ?

On Friday, July 5, 2019 at 7:25:08 AM UTC+2, Serdar Emirci wrote:

 <str:code>/League > <str:core>/League
 
 
Serdar EMIRCI


omar ahmed <omark...@gmail.com>, 5 Tem 2019 Cum, 00:43 tarihinde şunu yazdı:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/88b03928-dbbb-4b66-8661-499bdade3381%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Derek

unread,
Jul 7, 2019, 4:18:56 AM7/7/19
to Django users
Have you tried without the {'code'}

As per their example:

api1.png

omar ahmed

unread,
Jul 9, 2019, 4:08:11 PM7/9/19
to Django users
thank you Derek it works
now i read documentation
do you have any advice ?
Reply all
Reply to author
Forward
0 new messages