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:
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 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

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

you have to import form in
from accounts.forms import *

my ContactForm is located in accounts/

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. 

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

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

the value should be ''"

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

MySQL Client wasn't properly configured in your system.

1) Install pymysql
pip install pymysql

2) Then, edit the file in your project origin dir
import pymysql

TypeError: argument of type 'WindowsPath' is not iterable

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