from django.shortcuts import render
from django.http import HttpResponse
import urllib.request
import datetime
from xml.etree import ElementTree as ET
def dollar_evro(request):
id_dollar = "R01235"
id_evro = "R01239"
valuta = ET.parse(urllib.request.urlopen("http://www.cbr.ru/scripts/XML_daily.asp?date_req"))
for line in valuta.findall('Valute'):
id_v = line.get('ID')
if id_v == id_dollar:
rub_dollar = line.find('Value').text
if id_v == id_evro:
rub_evro = line.find('Value').text
today = datetime.date.today()
return HttpResponse("<h3>Hello " + rub_dollar + "</h3>")
from django.urls import path
from django.conf.urls import url
from django.views.generic import ListView, DetailView
from pages.models import posts
from . import views
urlpatterns = [
url(r'^$', views.dollar_evro, name='dollar_evro'),
path('', ListView.as_view(queryset=posts.objects.all().order_by("-date")[:20],
template_name="pages/wrapper.html"))
]