django.core.exceptions.ImproperlyConfigured:

2017-10-01 Thread harsh sharma
i am getting this error whenever i m trying to run django-admin runserver

django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but 
settings are not configured. You must eit
her define the environment variable DJANGO_SETTINGS_MODULE or call 
settings.configure() before accessing settings.

my wsgi file

import os
from django.conf import settings
from django.core.wsgi import get_wsgi_application

settings.configure(DEBUG=True)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")

application = get_wsgi_application()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/568cdb67-2a6f-4e3b-9ba8-842d0c721e7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with staticfiles in deployment

2017-10-01 Thread Alexander Joseph
environ allows you to use environment variables in your settings files, 
heres the docs
https://django-environ.readthedocs.io/en/latest/#

and my nginx config look like this... thanks

server {
listen 80;
server_name [domain name];
ssl_dhparam /etc/ssl/certs/dhparam.pem;

location = /favicon.ico { access_log off; log_not_found off; }
location /staticfiles/ {
root /home/business_management;
}

location / {
include proxy_params;
proxy_pass 
http://unix:/home/business_management/business_management.sock;
}
}





On Saturday, September 30, 2017 at 6:40:46 PM UTC-6, Alexander Joseph wrote:
>
> Hello,
>
> My site is deployed on an ubuntu/nginx/gunicorn droplet on digitalOcean. 
> For some reason my static files are not updating after running 
> collectstatic. I have access to older static files but cant make updates to 
> static files and see them in production. It works as it should on my 
> development computer. Its kind of like my staticfiles storage is some CDN 
> that I wasnt aware of and now when I run collectstatic its not putting the 
> files in the CDN anymore
>
> Below is my base settings configuration
>
> # settings/base.py
>
> import environ
>
> ROOT_DIR = environ.Path(__file__) - 3  # 
> (business_management/config/settings/base.py - 3 = business_management/)
> APPS_DIR = ROOT_DIR.path('business_management')
>
> # Load operating system environment variables and then prepare to use them
> env = environ.Env()
>
> # .env file, should load only in development environment
> READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)
>
> if READ_DOT_ENV_FILE:
> # Operating System Environment variables have precedence over 
> variables defined in the .env file,
> # that is to say variables from the .env files will only be used if 
> not defined
> # as environment variables.
> env_file = str(ROOT_DIR.path('.env'))
> print('Loading : {}'.format(env_file))
> env.read_env(env_file)
> print('The .env file has been loaded. See base.py for more 
> information')
>
>
> # DEBUG
> # 
> --
> # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
> DEBUG = env.bool('DJANGO_DEBUG', False)
>
>
> # Application definition
> # 
> --
>
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 
> 'django.contrib.sites',
> 'allauth',
> 'allauth.account',
> 'allauth.socialaccount',
> 'allauth_office365',
> 
> 'bootstrap4',
> 
> 'business_management.accounts',
> 'business_management.engineering',
> ]
>
> #SOCIALACCOUNT_ADAPTER = 'allauth_office365.adapter.SocialAccountAdapter'
> SOCIALACCOUNT_EMAIL_VERIFICATION = False
>
> SOCIALACCOUNT_PROVIDERS = {
> 'office365': {
>   'SCOPE': ['User.read',],
>   'USERNAME_FIELD': 'mail'
> }
> }
>
> MIDDLEWARE = [
> 'django.middleware.security.SecurityMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> ]
>
> ROOT_URLCONF = 'config.urls'
>
>
> TEMPLATES = [
> {
> # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
> 'DIRS': [
> str(APPS_DIR.path('templates')),
> ],
> 'OPTIONS': {
> # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
> 'debug': DEBUG,
> # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
> # 
> https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
> 'loaders': [
> 'django.template.loaders.filesystem.Loader',
> 'django.template.loaders.app_directories.Loader',
> ],
> # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.template.context_processors.i18n',
> 'django.template.context_processors.media',
> 'django.template.context_processors.static',
> 

Re: Help with staticfiles in deployment

2017-10-01 Thread Antonis Christofides
Hi,

1) What is environ? Could you point to its documentation page?

2) Could you show your nginx configuration?

Antonis Christofides
http://djangodeployment.com

On 2017-10-01 03:40, Alexander Joseph wrote:
> Hello,
>
> My site is deployed on an ubuntu/nginx/gunicorn droplet on digitalOcean. For
> some reason my static files are not updating after running collectstatic. I
> have access to older static files but cant make updates to static files and
> see them in production. It works as it should on my development computer. Its
> kind of like my staticfiles storage is some CDN that I wasnt aware of and now
> when I run collectstatic its not putting the files in the CDN anymore
>
> Below is my base settings configuration
>
> |
> # settings/base.py
>
> import environ
>
> ROOT_DIR = environ.Path(__file__) - 3  #
> (business_management/config/settings/base.py - 3 = business_management/)
> APPS_DIR = ROOT_DIR.path('business_management')
>
> # Load operating system environment variables and then prepare to use them
> env = environ.Env()
>
> # .env file, should load only in development environment
> READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)
>
> if READ_DOT_ENV_FILE:
>     # Operating System Environment variables have precedence over variables
> defined in the .env file,
>     # that is to say variables from the .env files will only be used if not
> defined
>     # as environment variables.
>     env_file = str(ROOT_DIR.path('.env'))
>     print('Loading : {}'.format(env_file))
>     env.read_env(env_file)
>     print('The .env file has been loaded. See base.py for more information')
>
>
> # DEBUG
> # 
> --
> # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
> DEBUG = env.bool('DJANGO_DEBUG', False)
>
>
> # Application definition
> # 
> --
>
> INSTALLED_APPS = [
>     'django.contrib.admin',
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.messages',
>     'django.contrib.staticfiles',
>     
>     'django.contrib.sites',
>     'allauth',
>     'allauth.account',
>     'allauth.socialaccount',
>     'allauth_office365',
>     
>     'bootstrap4',
>     
>     'business_management.accounts',
>     'business_management.engineering',
> ]
>
> #SOCIALACCOUNT_ADAPTER = 'allauth_office365.adapter.SocialAccountAdapter'
> SOCIALACCOUNT_EMAIL_VERIFICATION = False
>
> SOCIALACCOUNT_PROVIDERS = {
>     'office365': {
>       'SCOPE': ['User.read',],
>       'USERNAME_FIELD': 'mail'
>     }
> }
>
> MIDDLEWARE = [
>     'django.middleware.security.SecurityMiddleware',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.middleware.common.CommonMiddleware',
>     'django.middleware.csrf.CsrfViewMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.contrib.messages.middleware.MessageMiddleware',
>     'django.middleware.clickjacking.XFrameOptionsMiddleware',
> ]
>
> ROOT_URLCONF = 'config.urls'
>
>
> TEMPLATES = [
>     {
>         # See:
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
>         'BACKEND': 'django.template.backends.django.DjangoTemplates',
>         # See: 
> https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
>         'DIRS': [
>             str(APPS_DIR.path('templates')),
>         ],
>         'OPTIONS': {
>             # See:
> https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
>             'debug': DEBUG,
>             # See:
> https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
>             #
> https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
>             'loaders': [
>                 'django.template.loaders.filesystem.Loader',
>                 'django.template.loaders.app_directories.Loader',
>             ],
>             # See:
> https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
>             'context_processors': [
>                 'django.template.context_processors.debug',
>                 'django.template.context_processors.request',
>                 'django.contrib.auth.context_processors.auth',
>                 'django.template.context_processors.i18n',
>                 'django.template.context_processors.media',
>                 'django.template.context_processors.static',
>                 'django.template.context_processors.tz',
>                 'django.contrib.messages.context_processors.messages',
>                 # Your stuff: custom template context processors go here
>             ],
>         },
>     },
> ]
>
>
> WSGI_APPLICATION = 'config.wsgi.application'
>
>
> # Password validation
> # 
> --
> # 
> 

Re: get_ip_address() not working when used Custom Decorators

2017-10-01 Thread mitesh_django
Manu,

Try print kwargs.get('request')... 

You should get Django HTTPRequest Object, pass that to get_client_ip method.

On Thursday, September 28, 2017 at 3:03:09 PM UTC-4, Mannu Gupta wrote:
>
> While making a customer decorator in django, the code is here :-
>
> def owner_required(function):
> def wrap(request, *args, **kwargs):
> print(request)
> ip_address = get_client_ip(request)
> ip_exist = Node.objects.get(ip_address=ip_address)
> if ip_exist:
> return function(request, *args, **kwargs)
> else:
> raise PermissionDenied
> return wrap
>
> my code for get_ip_address() is :-
>
> def get_client_ip(request):
> """ Extract ip address from a Django request object
> """
> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
> if x_forwarded_for:
> ip = x_forwarded_for.split(',')[0]
> else:
> ip = request.META.get('REMOTE_ADDR')
> return ip
>
> The error i am getting is :-
>
> x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
> AttributeError: 'function' object has no attribute 'META'
>
>
> That get_client_ip() is working fine when used in normal function, but 
> don't know why it is not working when i am using it a decorator.
>
> What might be the problem ?
>
> Thanks in advance for replies.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/22e1890c-f522-425e-a260-1db7e4e9190a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: get_ip_address() not working when used Custom Decorators

2017-10-01 Thread Constantine Covtushenko
Sorry for late response,

I meant that you might using that decorator in 2 places.
And asked about that.

It seems like you specified `@owner_required` to decorate your view
function. But that decorator behave like `@owner_required()`.

With your last response I see that decorated function instead of `request`
receives `function all`. It looks like improperly used decorator.

More than that I do not have more ideas from what you provided.


On Sat, Sep 30, 2017 at 4:02 PM, Mannu Gupta 
wrote:

> Hello Constantine C,
>
> Thanks for your reply!
>
> What do you mean to say just one place ?
> I just printed the request using `print(request)` and getting this
> `` ( don't know what this actually is )
>
> Am i using the following approach.
> On Saturday, September 30, 2017 at 8:08:22 AM UTC+5:30, Constantine
> Covtushenko wrote:
>>
>> Hi Mannu,
>>
>> It seems like all are ok.
>> Sorry, but do you use it in just one place?
>> And do you see response in console from your print?
>>
>> Regards,
>> Constantine C.
>>
>> On Thu, Sep 28, 2017 at 4:36 PM, Mannu Gupta 
>> wrote:
>>
>>> I am just using it in a view function. For example:-
>>>
>>> @owner_required
>>> def all(request, **kwargs):
>>> pass
>>>
>>>
>>> On Friday, September 29, 2017 at 12:33:09 AM UTC+5:30, Mannu Gupta wrote:

 While making a customer decorator in django, the code is here :-

 def owner_required(function):
 def wrap(request, *args, **kwargs):
 print(request)
 ip_address = get_client_ip(request)
 ip_exist = Node.objects.get(ip_address=ip_address)
 if ip_exist:
 return function(request, *args, **kwargs)
 else:
 raise PermissionDenied
 return wrap

 my code for get_ip_address() is :-

 def get_client_ip(request):
 """ Extract ip address from a Django request object
 """
 x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
 if x_forwarded_for:
 ip = x_forwarded_for.split(',')[0]
 else:
 ip = request.META.get('REMOTE_ADDR')
 return ip

 The error i am getting is :-

 x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
 AttributeError: 'function' object has no attribute 'META'


 That get_client_ip() is working fine when used in normal function, but
 don't know why it is not working when i am using it a decorator.

 What might be the problem ?

 Thanks in advance for replies.

 --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/0e34ae73-5697-4a93-9402-c0ca1f4abd70%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Sincerely yours,
>> Constantine C
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/69879830-d7ad-4914-a8d4-7ac1ba1d8241%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXfYjnNZXBa-9Qo3jCtMuEzgBu76Q%3D36zgn_9242Y4Q4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting up Django for the first time, urls.py and settings.py

2017-10-01 Thread Jani Tiainen
Hi.

Urls changed so that you can't pass view as a string anymore.

If you're looking good tutorial Django Girls do have one. And it's using
recent djangi.


1.10.2017 2.40 ip. "drone4four"  kirjoitti:

> I’m playing with Django for the first time.  I am using a guide called, 
> “Python
> from Scratch - Creating a Dynamic Website
> ”  by [b]Tuts+ Code[/b] from
> YouTube.  It’s kinda old.  It was first posted in November 2011 and Django
> has evolved considerably.  I’ve had to try different commands, like
> ‘syncdb’ is no longer used.  Now it’s ‘migrate’. Yes, Tuts+ Code is over 6
> years old, but it’s the best tutorial in terms of explanations and teaching
> style. Anyways.
>
> I’m getting an error saying there is something wrong with my settings.py:
>
>> $ python ../manage.py runserver
>> Performing system checks...
>> Unhandled exception in thread started by > 0x7fe4876e76e0>
>> Traceback (most recent call last):
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/autoreload.py",
>> line 228, in wrapper
>>fn(*args, **kwargs)
>>  File "/home/gnull/.local/lib/python2.7/site-packages/
>> django/core/management/commands/runserver.py", line 125, in inner_run
>>self.check(display_num_errors=True)
>>  File "/home/gnull/.local/lib/python2.7/site-packages/
>> django/core/management/base.py", line 359, in check
>>include_deployment_checks=include_deployment_checks,
>>  File "/home/gnull/.local/lib/python2.7/site-packages/
>> django/core/management/base.py", line 346, in _run_checks
>>return checks.run_checks(**kwargs)
>>  File "/home/gnull/.local/lib/python2.7/site-packages/
>> django/core/checks/registry.py", line 81, in run_checks
>>new_errors = check(app_configs=app_configs)
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py",
>> line 16, in check_url_config
>>return check_resolver(resolver)
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py",
>> line 26, in check_resolver
>>return check_method()
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py",
>> line 254, in check
>>for pattern in self.url_patterns:
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py",
>> line 35, in __get__
>>res = instance.__dict__[self.name] = self.func(instance)
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py",
>> line 405, in url_patterns
>>patterns = getattr(self.urlconf_module, "urlpatterns",
>> self.urlconf_module)
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py",
>> line 35, in __get__
>>res = instance.__dict__[self.name] = self.func(instance)
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py",
>> line 398, in urlconf_module
>>return import_module(self.urlconf_name)
>>  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
>> import_module
>>__import__(name)
>>  File 
>> "/home/gnull/Dropbox/TECH/python/2017/beginning-Django/G_Thomas/G_Thomas/urls.py",
>> line 21, in 
>>url(r'^$', 'blog.views.home', name='home')
>>  File 
>> "/home/gnull/.local/lib/python2.7/site-packages/django/conf/urls/__init__.py",
>> line 85, in url
>>raise TypeError('view must be a callable or a list/tuple in the case
>> of include().')
>> TypeError: view must be a callable or a list/tuple in the case of
>> include().
>
>
> Those last couple of lines in this error message are instructive. I’m not
> sure about the case of include() in urls.py but my url declaration indeed
> is a tuple.  Why is my shell telling me there is something wrong with my
> tuple when it should be a tuple?  I also swapped out the parentheses with
> square brackets to see if it would take a list as it says it can.  Either
> way, same error.
>
> Here are the contents of my urls.py:
>
> from django.conf.urls import *
>> from django.contrib import admin
>> admin.autodiscover()
>> urlpatterns = ['',
>> # url(r'^admin/', admin.site.urls),
>> url(r'^$', 'blog.views.home', name='home')
>> ]
>
>
> Take note of the square brackets and lack of the patterns function (as
> compared to the presence of the function in the code from the teacher
> below). Also commented out above is the default urlpattern that came with
> Django 1.11.
>
> So the urlpattern in Tuts+ Code’s actually looks like this:
>
> from django.conf.urls.defaults import patterns, include, url
>> from django.contrib import admin
>> urlpatterns = patterns (‘’,
>> url(r'^$', ‘FirstBlog.views.home’, name='home'),
>> )
>
>
> Addressing a related issue with importing the name pattern in urls.py for
> Django, some folks over on stackoverflow describe their Djanog urls.py
> 
> configuration file use a simple variable declaration for urlpatterns and
> don’t 

Setting up Django for the first time, urls.py and settings.py

2017-10-01 Thread drone4four


I’m playing with Django for the first time.  I am using a guide called, “Python 
from Scratch - Creating a Dynamic Website 
”  by [b]Tuts+ Code[/b] from 
YouTube.  It’s kinda old.  It was first posted in November 2011 and Django 
has evolved considerably.  I’ve had to try different commands, like 
‘syncdb’ is no longer used.  Now it’s ‘migrate’. Yes, Tuts+ Code is over 6 
years old, but it’s the best tutorial in terms of explanations and teaching 
style. Anyways.

I’m getting an error saying there is something wrong with my settings.py:

> $ python ../manage.py runserver
> Performing system checks...
> Unhandled exception in thread started by  0x7fe4876e76e0>
> Traceback (most recent call last):
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/autoreload.py", 
> line 228, in wrapper
>fn(*args, **kwargs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py",
>  
> line 125, in inner_run
>self.check(display_num_errors=True)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 359, in check
>include_deployment_checks=include_deployment_checks,
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 346, in _run_checks
>return checks.run_checks(**kwargs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/registry.py",
>  
> line 81, in run_checks
>new_errors = check(app_configs=app_configs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py", 
> line 16, in check_url_config
>return check_resolver(resolver)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py", 
> line 26, in check_resolver
>return check_method()
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 254, in check
>for pattern in self.url_patterns:
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py", 
> line 35, in __get__
>res = instance.__dict__[self.name] = self.func(instance)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 405, in url_patterns
>patterns = getattr(self.urlconf_module, "urlpatterns", 
> self.urlconf_module)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py", 
> line 35, in __get__
>res = instance.__dict__[self.name] = self.func(instance)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 398, in urlconf_module
>return import_module(self.urlconf_name)
>  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
>__import__(name)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/beginning-Django/G_Thomas/G_Thomas/urls.py",
>  
> line 21, in 
>url(r'^$', 'blog.views.home', name='home')
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/conf/urls/__init__.py",
>  
> line 85, in url
>raise TypeError('view must be a callable or a list/tuple in the case of 
> include().')
> TypeError: view must be a callable or a list/tuple in the case of 
> include().


Those last couple of lines in this error message are instructive. I’m not 
sure about the case of include() in urls.py but my url declaration indeed 
is a tuple.  Why is my shell telling me there is something wrong with my 
tuple when it should be a tuple?  I also swapped out the parentheses with 
square brackets to see if it would take a list as it says it can.  Either 
way, same error.

Here are the contents of my urls.py:

from django.conf.urls import *
> from django.contrib import admin
> admin.autodiscover()
> urlpatterns = ['',
> # url(r'^admin/', admin.site.urls),
> url(r'^$', 'blog.views.home', name='home')
> ]


Take note of the square brackets and lack of the patterns function (as 
compared to the presence of the function in the code from the teacher 
below). Also commented out above is the default urlpattern that came with 
Django 1.11.  

So the urlpattern in Tuts+ Code’s actually looks like this:

from django.conf.urls.defaults import patterns, include, url
> from django.contrib import admin
> urlpatterns = patterns (‘’,
> url(r'^$', ‘FirstBlog.views.home’, name='home'),
> )


Addressing a related issue with importing the name pattern in urls.py for 
Django, some folks over on stackoverflow describe their Djanog urls.py 
 
configuration file use a simple variable declaration for urlpatterns and 
don’t bother with the function patterns() the way the YouTuber explains 
that it should look like.  Like, the YouTuber uses: ‘*urlpatterns = 
patterns( ... )*’ whereas the stackoverflow people set it as: ‘*urlpatterns 
= [ ‘’, ...]'*.  

I get the sense that I am slightly off in my understanding of the issue.