Category

Django

Category

Why does DEBUG=False setting make my django Static Files Access fail? In urls.py we need to add this line: from django.views.static import serve add those two urls in urlpatterns: url(r’^media/(?P<path>.*)$’, serve,{‘document_root’: settings.MEDIA_ROOT}), url(r’^static/(?P<path>.*)$’, serve,{‘document_root’: settings.STATIC_ROOT}), and both static and media files were accesible when DEBUG=FALSE.

Python Django Errno 54 ‘Connection reset by peer’ I noticed that it was always resetting after not finding a favicon. Even though I never explicitly loaded one, django appears to try and load a default one from the root of the project. This doesn’t happen for any of the other devs working on the project. If anyone else stumbles upon this i used favicon.io to make a simple text one. Then I loaded it into…

How to Create a Video Uploader with Django in Admin panel open models.py from django.db import models # Create your models here. class Videos(models.Model): title = models.CharField(max_length=100) video = models.FileField(upload_to=’videos/’) class Meta: verbose_name = ‘video’ verbose_name_plural = ‘videos’ def __str__(self): return self.title Run Migrate Command python manage.py makemigrations python manage.py migrate

Solved: django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library When working with Django, you may encounter an error as below, django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log rest_framework static tz Solution : This error can be resolved by django_project/settings.py and add libraries as following in TEMPLATES ‘libraries’: { ‘staticfiles’: ‘django.templatetags.static’, }, So, the settings.py may look like as below, TEMPLATES = [ {…

Set favicon in django admin Override favicon Django base.html in the template and put it under admin directory like my_app/templates/admin/base.html Add {% block extrahead %} to the overriding template. {% extends ‘admin/base.html’ %} {% load static %} {% block extrahead %} <link rel=”shortcut icon” href=”{% static ‘images/GH_favicon.png’ %}” /> {% endblock %}

https://www.youtube.com/watch?v=OGAGYPi_Z1c How to Django Send Email with Attachment – Django Setup Gmail Account for Email API Configure Django for Gmail SMTP server Go to your settings.py file and add the following parameters EMAIL_USE_TLS = True EMAIL_HOST = ‘smtp.gmail.com’ EMAIL_PORT = 587 EMAIL_HOST_USER=’gmail@gmail.com’ EMAIL_HOST_PASSWORD=’passs!@#$%’ Open your html form and put code <form action=”{% url ‘contact_mail’ %}” method=”post”> {% csrf_token %} <div class=”form-group”> <select class=”form-control” name=”topic” required> <option>Topic*</option> <option value=”New Customer”>New Customer</option> <option>Employment</option> <option>Existing Customer </option> <option>Partner</option>…

Django: Advantages of Using Django 1. Security Users of Django will be impressed with the level of protection from all possible security-related errors like clickjacking, SQL injections, cross-site scripting, and forgery. 2. Full-featured Django goes well with lots of extra features, which main aim is to help with sitemaps, user authentication, and content administration. The following bonuses assist implementation in every step of web development.Web development 3. Scalability Django is the best choice for dealing with…