I'd allow anything to be passed in the url
, then I would validate the url in the view:
url(r'^save/(?P<url>.*)/$', views.save_url, name='save_url'),
Then, the view needs to validate the url:
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError
def save_url(request, url):
url_validator = URLValidator(verify_exists=False)
try:
url_validator(url)
except ValidationError:
print 'Not a valid URL'
You would also probably need to unquote
the url before validating it.