def general(request): if request.method == 'POST': form = URLShortenerForm(request.POST) new_url = md5(str(form['url']).encode()).hexdigest() print(f"{str(form['url']) = }") form.new_url = new_url print(f"{form.new_url = }") form.save() if form.is_valid(): print(f"{form.cleaned_data = }") form.save() pass
Public
Type hints help humans and linters (like mypy
) to understand what to expect "in" and "out" for a function. Not only it serves as a documentation for others (and you after some time, when the code is wiped from your "brain cache"), but also allows using automated tools to find type errors.
Almost always class-based views are more readable and extendable than plain "function" views. As an example, CBVs allow you to handle GET, POST and other verbs in separate methods, which adds readability to your code.
print()
is a nice way to output to stdout. But one day you'll need to not only write to stdout, but also, say, to a file. Another day you'll need to output only severe errors' messages, and nothing else. This all could be solved if using logging
module. Usually it's as easy as from logging import getLogger; log = getLogger(__name__)
.
Seems like things could be organized in a better way.
Saving form twice seems weird.
Create new review request