I'm trying to sort the problem of determining if a URL is available to be used as a first-level url path for objects. For example: www.myapp.com/username_1 would be available if no username_1 has previously existed.
One solution I found is this but the solution is not correct. The validation part:
def clean_username(self):
username = super(NewRegistrationForm, self).clean_username()
try: resolve(urlparse('/' + username + '/')[2])
except Resolver404, e:
return username
raise ValidationError(_(u'This username does not create '
u'a valid URL. Please choose '
u'another'))
would always raise an error. It seams that there needs to be a way to check if a URL returns a 404 or not. I could use urllib however I was wondering if there was a better solution to this problem?
Many thanks.