DEV Community

Discussion on: Django view doesn't output correctly

Collapse
 
highcenburg profile image
Vicente G. Reyes

uhhh this doesn't return the online domains.

Collapse
 
vergeev profile image
Pavel Vergeev

Wow :O

OK, at this point I can only suggest two things.

  1. Use breakpoint() to inspect the variables inside the view;

  2. Use this code for your reference: github.com/vergeev/17_sites_monito....

Tell me if something new comes up. :)

Thread Thread
 
highcenburg profile image
Vicente G. Reyes

Here's what I did

def pingDomain(request, page, url):
    page_object = get_object_or_404(Table, page=page)
    url = page_object.page
    response = requests.head(url)
    try:
        return requests.head(url).ok
    except requests.exceptions.ConnectionError:
        return False
    context = {
        'online': response.ok
    }
    return render(request, 'home.html', context)

Returns nothing :(