repos
/ status-django master

status-django

mirror archived upstream

Self-hostable uptime monitor and status page on Django: HTTP checks, Lighthouse audits, SEO crawls, and email and Discord alerts.

djangodockerhandcodedpythonself-hostedsqlitestatus-pageuptime-monitoringvite

578 B · 23 lines · Python Raw History
 1import requests
 2
 3from django import forms
 4
 5from .models import Property
 6
 7
 8class PropertyForm(forms.ModelForm):
 9    class Meta:
10        model = Property
11        fields = ('url',)
12
13    def clean_url(self):
14        url = self.cleaned_data['url']
15        if not url.startswith('http'):
16            url = 'http://' + url
17        try:
18            r = requests.get(url)
19            r.raise_for_status()
20        except requests.exceptions.RequestException:
21            raise forms.ValidationError('Invalid URL')
22        return r.url  # NOTE: requests' "Final URL location of Response."