Fullstack Fruit & Veg Shop: A web application developed with HTML, CSS, and JavaScript for the frontend, and Django for the backend. Features include user authentication, a product catalogue, shopping cart functionality, and order management. and much more
try:
NewsletterSubscription.objects.create(user=user, email=email)
except IntegrityError: # Except block to catch the error
error_msg = \"A user with that email already exists.\"
return is_valid, error_msg
Workflow
Users can subscribe only if they have not previously registered with that email address.
If they have already subscribed, they will receive an alert indicating that they cannot use that email again.
If the subscription is successful, they will be shown a tailored message confirming their subscription.
Added a
try-except
block inviews.py
to prevent the model from creating a subscription when an email already exists in the database.Previous Code:
Updated Code:
Workflow Users can subscribe only if they have not previously registered with that email address. If they have already subscribed, they will receive an alert indicating that they cannot use that email again. If the subscription is successful, they will be shown a tailored message confirming their subscription.