Django – [Errno 111] Connection refused

Looks like you are trying to send a mail (send_mail()) and your mail settings in your settings.py are not correct. You should check the docs for sending emails. For debugging purposes you could setup a local smtpserver with this command: python -m smtpd -n -c DebuggingServer localhost:1025 and adjust your mail settings accordingly: EMAIL_HOST = … Read more

How to get URL of current page, including parameters, in a template?

Write a custom context processor. e.g. def get_current_path(request): return { ‘current_path’: request.get_full_path() } add a path to that function in your TEMPLATE_CONTEXT_PROCESSORS settings variable, and use it in your template like so: {{ current_path }} If you want to have the full request object in every request, you can use the built-in django.core.context_processors.request context processor, … Read more

Django bulk_create with ignore rows that cause IntegrityError?

This is now possible on Django 2.2 Django 2.2 adds a new ignore_conflicts option to the bulk_create method, from the documentation: On databases that support it (all except PostgreSQL < 9.5 and Oracle), setting the ignore_conflicts parameter to True tells the database to ignore failure to insert any rows that fail constraints such as duplicate … Read more

Django’s ModelForm unique_together validation

I solved this same problem by overriding the validate_unique() method of the ModelForm: def validate_unique(self): exclude = self._get_validation_exclusions() exclude.remove(‘problem’) # allow checking against the missing attribute try: self.instance.validate_unique(exclude=exclude) except ValidationError, e: self._update_errors(e.message_dict) Now I just always make sure that the attribute not provided on the form is still available, e.g. instance=Solution(problem=some_problem) on the initializer.

tech