Saturday 29 June 2019

Creating a New Project

Navigate to where you want to store your Django apps
like E drive or F drive  1) cd f:
then
2) django-admin startproject projectname


Friday 28 June 2019

NameError: name 'include' is not defined

you have to import include

from django.conf.urls import include

from django.core import urlresolvers ImportError: cannot import name 'urlresolvers' from 'django.core'

This is Django Version issue.

For versions > 1.10, use

from django.urls import reverse

instead of  " from django.core import urlresolvers "

ImportError: failed to find libmagic. Check your installation

1) uninstall python-magic
pip uninstall python-magic

2) install python-magic-bin==0.4.14
pip install python-magic-bin==0.4.14

Monday 24 June 2019

Getting Server Error (500) on starting the server in local

Set DEBUG = True in settings.py file

Note: Make sure to set its value to False in production.

ImportError: cannot import name 'patterns' from 'django.conf.urls'

pattern is removed from 1.8+ DJango version

You can write

from django.conf.urls import include, url

urlpatterns = [
.
.
.
]

Saturday 22 June 2019

NameError at /contact_us/ name 'ContactForm' is not defined

Cause:
You didn't import ContactForm basically form in your views.py file
but, you are referring the form in views.py
form = ContactForm()

Resolution:
you have to import form in views.py
from accounts.forms import *

my ContactForm is located in accounts/forms.py

UnboundLocalError at /contact_us/ local variable 'form' referenced before assignment


You defined the form variable in this if request.method == 'POST': block. If you access the view with a GET request form gets not defined. 

Cause:
def contact_us(request):
   
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():

Resolution:
def contact_us(request):
    form = ContactForm(request.POST)
    if request.method == 'POST':
 
        if form.is_valid():


socket.gaierror: [Errno 11001] getaddrinfo failed

There must be an error in
EMAIL_HOST attribute in settings.py

the value should be ''smtp.gmail.com"

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

MySQL Client wasn't properly configured in your system.

Resolution:
1) Install pymysql
pip install pymysql

2) Then, edit the __init__.py file in your project origin dir
import pymysql
pymysql.install_as_MySQLdb()

TypeError: argument of type 'WindowsPath' is not iterable

 Please make to modify settings.py file: DATABASES = { 'default' : { 'ENGINE' : 'django.db.backends.sqlite3&...