Django URLS help app not defined

625 views
Skip to first unread message

G Z

unread,
May 6, 2014, 1:09:51 AM5/6/14
to django...@googlegroups.com
project name = provisioning
app name = vmware

In my projects urls.py I have the following. I assume I set the new url link customers to myapp.urls because im watching a youtube video and thats what he did.

    from django.conf.urls import patterns, include, url
    from django.contrib import admin
    admin.autodiscover()
    urlpatterns = patterns('',
        url(r'^admin/', include(admin.site.urls)),
        url(r'^customers/', include(vmware.urls)), #i'm assuming its my appsname.urls
    )

In my vmware directory I have the urls.py file as the video had me design. To which I have the following code:

    from django.conf.urls import patterns, include, url
    from django.view.generic import ListView
    from vmware.models import Customer
    
    urlpatterns = patterns('',
                          url(r'^customers/', ListView.as_view(
                                    queryset=Customer.objects.all().order_by"-id")[:100],
                                    template_name="VMS.html")),
    )

Now when I syncdb and runserver I get no erros. But when I try to resolve the page I get the following. It says vmware is not defined but it is defined in my installed apps.

Environment:


Request Method: GET

Django Version: 1.6.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'vmware')
Installed Middleware:
('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')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                 resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  337.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  365.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  360.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  40.         __import__(name)
File "/root/djangoprojects/provisioning/provisioning/urls.py" in <module>
  12.     url(r'^customers/', include(vmware.urls)),

Exception Type: NameError at /admin/
Exception Value: name 'vmware' is not defined

Rafael E. Ferrero

unread,
May 6, 2014, 7:11:29 AM5/6/14
to django...@googlegroups.com
I think that you fail on trying to setup the admin site for your proyect.
check this out https://docs.djangoproject.com/en/1.6/ref/contrib/admin/

--
RAFAEL FERRERO
Chief Officer Technology
San Francisco Cba. | Argentina
+54 9 356251 4856
www.perseux.com


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/031cb075-cdd8-47bf-9a6f-6135209deeb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

G Z

unread,
May 6, 2014, 12:06:29 PM5/6/14
to django...@googlegroups.com
I'm not trying to set up the admin stie. I have already done that the admin site works im trying to set up the /customers site. Which I have defined below. I have it set in the projects urls.py to link to vmware.urls then i have the urls.py in the app vmware pointing to my templates to display data but its telling me vmware is undefined.

G Z

unread,
May 6, 2014, 12:07:42 PM5/6/14
to django...@googlegroups.com
and yes vmware is defined in installed apps.

Davide Scatto

unread,
May 6, 2014, 12:08:01 PM5/6/14
to django...@googlegroups.com
it seems in yr project urls.py you don't import vmware.
 
  from django.conf.urls import patterns, include, url
  from django.contrib import admin
  from . import vmware

  urlpatterns = patterns....
 

G Z

unread,
May 6, 2014, 12:28:28 PM5/6/14
to django...@googlegroups.com
so in my project.urls file i put

 from . import vmware

do i have to add anything to my apps.urls because i got the following error after adding the folllowing

from django.contrib import admin
admin.autodiscover()
from . import vmware

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'provisioning.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^customers/', include(vmware.urls)),
)


Error
Environment:


Request Method: GET

  5. from . import vmware

Exception Type: ImportError at /
Exception Value: cannot import name vmware

C. Kirby

unread,
May 6, 2014, 1:21:50 PM5/6/14
to django...@googlegroups.com
Please post your project structure - that will help to clear up the import

G Z

unread,
May 6, 2014, 1:38:22 PM5/6/14
to django...@googlegroups.com
I'm running 1.6.4

Project Structure
Project name: provisioning
App Name: vmware

 
/djangoprojects/provisioning/provisioning/urls.py
<code>

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()
from . import vmware

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'provisioning.views.home', name='home$
    # url(r'^blog/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^customers/', include(vmware.urls)),
)
</code>

/djangoprojects/provisioning/vmware/urls.py

<code>
from django.conf.urls import patterns, include, url
from django.view.generic import ListView
from vmware.models import Customer

urlpatterns = patterns('',
                      url(r'^customers/', ListView.as_$
                                queryset=Customer.obje$
                                template_name="VMS.htm$
)
</code>

/djangoprojects/provisioning/provisioning/settings.py 
<code>

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'vmware',
)

</code>

Directory Structure

directory structure provisioning is the project vmware is the app.
drwxr-xr-x 4 root root 4096 May  5 20:12 .
drwxr-xr-x 3 root root 4096 May  5 19:09 ..
-rw-r--r-- 1 root root  255 May  5 19:09 manage.py
drwxr-xr-x 2 root root 4096 May  6 11:15 provisioning
drwxr-xr-x 3 root root 4096 May  6 11:15 vmware


/djangoprojects/provisioning/vmware/modesl.py

<code> 
from django.db import models

# Create your models here.

class Customer(models.Model):
    NAME = models.CharField(max_length=200)
    WEBSITE = models.CharField(max_length=200)
    PHONE = models.CharField(max_length=200)
    EMAIL = models.CharField(max_length=200)
    ADDRESS = models.CharField(max_length=200)
    VMIDS = models.CharField(max_length=200)

    def __unicode__(self):
        return self.NAME
#               return self.NAME

class Vms(models.Model):
    VMID  = models.CharField(max_length=200)
    VMNAME = models.CharField(max_length=200)
    VMSTATUS = models.CharField(max_length=200)
    CUSTOMERID = models.ForeignKey(Customer)

class Vmspecs(models.Model):
    CPUS =  models.CharField(max_length=200)
    CORES =  models.CharField(max_length=200)
    MEMORY =  models.CharField(max_length=200)
    HDSPACE =  models.CharField(max_length=200)
    OS =  models.CharField(max_length=200)
    UPTIME = models.CharField(max_length=200)
    VMID = models.ForeignKey(Vms)

  #  choice_text = models.CharField(max_length=200)
</code>

need anything else. 

C. Kirby

unread,
May 6, 2014, 1:48:09 PM5/6/14
to django...@googlegroups.com
G Z,
That is a somewhat odd project structure. Also, the ls you posted:


directory structure provisioning is the project vmware is the app.
drwxr-xr-x 4 root root 4096 May  5 20:12 .
drwxr-xr-x 3 root root 4096 May  5 19:09 ..
-rw-r--r-- 1 root root  255 May  5 19:09 manage.py
drwxr-xr-x 2 root root 4096 May  6 11:15 provisioning
drwxr-xr-x 3 root root 4096 May  6 11:15 vmware

Does not match the path you posted:
/djangoprojects/provisioning/vmware/modesl.py

In particular there is not __init__.py in that root folder, so imports cannot traverse through it. Take a look at https://github.com/twoscoops/django-twoscoops-project for a project layout. If you use that the project_name would be provisioning and you would put the vmware app in

django-twoscoops-project / project_name / project_name /

Have you done the tutorial on django yet? I think you will find the answer to most of the questions you have posted if you walk through and do the tutorial: https://docs.djangoproject.com/en/1.6/intro/tutorial01/

Kirby

G Z

unread,
May 6, 2014, 2:05:30 PM5/6/14
to django...@googlegroups.com
I'm following the django tutorial

the project is provisioning
I created the folder provisioning folder, then ran startproject provisioning which has manage.py then it creates the subfolder provisioning which has the init.py file and settings etc.
then from the root directory of my project folder the first level or provisioning where manage.py is i used startapp command and it created vmware so from the root directory of the project provisioning it created provisioning for the project and it created vmware. That is following the tutorial on djangoproject.com

so how did I do it wrong?


On Monday, May 5, 2014 11:09:51 PM UTC-6, G Z wrote:

G Z

unread,
May 6, 2014, 2:16:46 PM5/6/14
to django...@googlegroups.com

C. Kirby

unread,
May 6, 2014, 2:18:24 PM5/6/14
to django...@googlegroups.com
Sorry, it's been a while since I looked at the tutorial, to make the tutorial more straightforward it uses a simplified project layout.
I looked at your urls again, and the error is that you forgot quotes.
    url(r'^customers/', include(vmware.urls)),
should be
    url(r'^customers/', include('vmware.urls')),

and you should remove the from . import vmware

Kirby

C. Kirby

unread,
May 6, 2014, 2:20:47 PM5/6/14
to django...@googlegroups.com
I strongly recommend the tutorial provided by django, and I would do the tutorial as it is to start, not with your own models. Really understand the concepts as they are written, then apply those concepts to your project.

Kirby

G Z

unread,
May 6, 2014, 2:38:34 PM5/6/14
to django...@googlegroups.com
Whats wrong with this 

<code>
from django.conf.urls import patterns, include, url
from django.view.generic import ListView
from vmware.models import Customer

urlpatterns = patterns(' ',
                      url(r'^customers/', ListView.as_view(
                                queryset=Customer.objects.all().order_by"-id")[:100],
                                template_name="VMS.html")),
)
 </code>

This should take the model Customer and take the fields -id in the database and order them by that correct.

C. Kirby

unread,
May 6, 2014, 2:43:12 PM5/6/14
to django...@googlegroups.com
At first glance you are missing a paren:
   queryset=Customer.objects.all().order_by"-id")[:100]
should be:
   queryset=Customer.objects.all().order_by("-id")[:100]

Are you using an IDE? It should have picked that up

kirby

G Z

unread,
May 6, 2014, 4:40:50 PM5/6/14
to django...@googlegroups.com
Thanks so much one last thing

Page not found (404)

Request Method:GET
Request URL:http://pythondev.enki.co:8001/customers

Using the URLconf defined in provisioning.urls, Django tried these URL patterns, in this order:

  1. ^admin/
  2. ^customers/

The current URL, customers, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

I got it to work but its still not seeing the customers url is my regex wrong? 

Rafael E. Ferrero

unread,
May 6, 2014, 5:23:29 PM5/6/14
to django...@googlegroups.com
if you try http://pythondev.enki.co:8001/admin works just fine ?


--
Rafael E. Ferrero


--
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 http://groups.google.com/group/django-users.

G Z

unread,
May 6, 2014, 5:32:12 PM5/6/14
to django...@googlegroups.com
yea the admin works perfectly fine no issues.


On Monday, May 5, 2014 11:09:51 PM UTC-6, G Z wrote:

G Z

unread,
May 6, 2014, 5:33:38 PM5/6/14
to django...@googlegroups.com

The admin page works fine only the other two don't

Project Structure Project Root Directory: provisioning/ this is where manage.py lives 

Project Settings Directory provisioning/provisioning/settings.py 

App Directory provisioning/vmware 

template directory /provisioning/vmware/templates/ this is wehre vms.html lives

from my project urls.py file

GNU nano 2.2.6                      File: provisioning/urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    # url(r'^$', 'provisioning.views.home', name='home'),
        url(r'^admin/', include(admin.site.urls)),
        url(r'^customers', include('vmware.urls')),
        url(r'^test/', include('vmware.urls')),
)

from my app urls.py file:

from django.conf.urls import patterns, include, url
from django.views.generic.list import ListView
from vmware.models import Customer

urlpatterns = patterns('',
        url(r'^customers', ListView.as_view(
                queryset=Customer.objects.all().order_by("-id")[:100],
                        template_name="vms.html")),
)

urlpatterns = patterns('',
        url(r'^test/', ListView.as_view(
                queryset=Customer.objects.all().order_by("-id")[:100],
                        template_name="vms.html")),
)

and then this is the error im getting

Page not found (404)
Request Method: GET
Request URL:    http://pythondev.enki.co:8001/test
Using the URLconf defined in provisioning.urls, Django tried these URL patterns, in this order:
^admin/
^customers
^test/
The current URL, test, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


G Z

unread,
May 6, 2014, 5:41:08 PM5/6/14
to django...@googlegroups.com
ok I figured it out all i had to do was change my app urls.py and take out customers so now its like this 

from django.conf.urls import patterns, include, url
from django.views.generic.list import ListView
from vmware.models import Customer

urlpatterns = patterns('',
        url(r'^', ListView.as_view(
                queryset=Customer.objects.all().order_by("-id")[:100],
                        template_name="vms.html")),
)





On Monday, May 5, 2014 11:09:51 PM UTC-6, G Z wrote:

Rafael E. Ferrero

unread,
May 6, 2014, 5:42:56 PM5/6/14
to django...@googlegroups.com
if you visit http://www.fsorgosuardi.com.ar/eventos you go to activos views
if you visit http://www.fsorgosuardi.com.ar/eventos/ampliar/something-here you go to activos views with parameters
if you visit http://www.fsorgosuardi.com.ar/eventos/archivados/ you go to archivados views (its inactive for now)

what i see is that you construct something like
www.domain.com/customers/customers

--
Rafael E. Ferrero


--
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 http://groups.google.com/group/django-users.

Tom Evans

unread,
May 7, 2014, 12:37:26 PM5/7/14
to django...@googlegroups.com
Check closely what you are being told here.

Django tried these patterns:

"^admins/"
"^customers/"

and neither matched the current URL "customers".

Computers are precise machines - "customers" is not the same as "customers/". You must be precise.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages