Reputation: 24131
I have a general design question about Django. Suppose I want to create a template with a registration form, which lets the user type in their name and press a submit button. I then want to check in the database whether a user already exists with this name. If this name does exist, I want to inform the user, and return back to the template. Otherwise, I want to create this user in the database.
The way I can think to do this is to look in the database and see if a user with this name exists, and if it does, I would add an extra bit of information to the context sent to the template. This extra bit of information would inform my template to display a line saying something like "{{ username }} already exists." If the information does not exist, then the template does not display anything.
Is this a suitable solution? My only issue now then, is how can I determine, in the template, whether a variable in the context does or does not exist?
Thanks!
Upvotes: 0
Views: 87
Reputation: 12037
This is a job for Django forms! These are used to validate input from the user.
Upvotes: 1