Saturday, 13 February 2021

TypeError: argument of type 'WindowsPath' is not iterable

 Please make to modify settings.py file:


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': str(os.path.join(BASE_DIR, "db.sqlite3"))
    } 

} 

Friday, 9 October 2020

'staticfiles' is not a registered tag library.

 {% load staticfiles %} and {% load admin_static %} were deprecated in django 2.1, and removed in django 3.1.

If you have any of the following in your template:

{% load staticfiles %}
{% load static from staticfiles %}
{% load admin_static %}

You should replace the tag with simply:

{% load static %}

Thursday, 14 May 2020

GITHUB: Add/ Push a folder to git


1. Initialize the Git Repo
     git init

2. Add the files to Git index
    git add -A

3. Commit Added Files
    git commit -m "my commit"

4. Add new remote origin (GitHub)
    git remote add origin git@....

5. Push to GitHub
git push -u -f origin master

Tuesday, 21 January 2020

URL Mapping

from django.contrib import admin
from django.urls import path
from django.conf.urls import include


urlpatterns= [
   path('admin/', admin.site.urls),
   path('', include('DJP.urls')),
]



from django.urls import path
from . import views
from django.conf.urls import url

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    path('', views.home, name= 'home'),
   # url(r'^home/(?P<id>\d+)/$', views.data, name= 'data'),
]



from django.shortcuts import render

# Create your views here.

from .models import *

# Create your views here.

def home(request):
    return render(request, 'DJP/home.html')








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