Setting up Django

80 views
Skip to first unread message

ofeyofey

unread,
Jan 16, 2016, 4:27:31 PM1/16/16
to Django users
Hi,

I am following the Django tutorial on the Django site. Getting errors when i try to make migrations after adding the app to the list of apps in mathGenerator/settings.py

Setting up Django on a raspberry Pi. I don't think the fact that it is on api should make any difference becasue it is basically running.

It is here https://docs.djangoproject.com/en/1.9/intro/tutorial02/

In the previous tutorial I created a project calles mathGenerator and a app called generator.

Created the project with django_admin startproject mathGenerator

Ran the server with $python manage.py runserver

And i can see the site in my browser. So this ia working fine.

Then I created an app called generator using

$python manage.py startapp generator

In generator/nviews.py I put

from django.http import HttpResponse
code = "<html><head><style>body{background-color:rgb(100,0,200);}</style></head><body><br>Django test site <br><br>Hosted on a Raspberry Pi<br><br><button>Press me!</button></body></html>"
# Create your views here.
def index(request):
    return HttpResponse(code)

and in generator/urls.py I put

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

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

In mathGenerator/urls.py I put

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^generator/', include('generator.urls')),   
    url(r'^admin/', include(admin.site.urls)),
]

This works find when I go to

127.0.0.1:8000/generator

Next I used

$python manage.py migrate

Then i created a model in generator/models.py

from django.db import models

# Create your models here.
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimefield('date published')

class Choice(models.model):
    question = models.FioreignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

Adding to app to the list of apps in mathGenerator/settings.py

INSTALLED_APPS = [
    'generator.apps.generatorConfig',   
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]


Then I try to make migrations and I get this error,

pi@raspberrypi ~/DjangoPi/mathGenerator $ python manage.py makemigrations generator
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 112, in create
    mod = import_module(mod_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named apps

What am I doing wrong?

Any help would be greatly appreciated,

Thanks



Vijay Khemlani

unread,
Jan 16, 2016, 4:54:21 PM1/16/16
to django...@googlegroups.com
your app is called "generator", that's all you need to put in INSTALLED APPS

also, I'm not sure if this matters, but I tend to put my apps after the ones bundled with django.

--
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/msgid/django-users/d70cebe8-277a-43f8-99c1-edbac9cecdbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ofeyofey

unread,
Jan 16, 2016, 6:51:50 PM1/16/16
to Django users
Hi,

Thank you so much for looking at this.

I change setting.py to

INSTALLED_APPS = [
    'generator',   
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

and ran $python manage.py migrate

and get

pi@raspberrypi ~/DjangoPi/mathGenerator $ python manage.py migrate

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)

  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/pi/DjangoPi/mathGenerator/generator/models.py", line 4, in <module>
    class Question(models.Model):
  File "/home/pi/DjangoPi/mathGenerator/generator/models.py", line 6, in Question

    pub_date = models.DateTimefield('date published')
AttributeError: 'module' object has no attribute 'DateTimefield'

Thanks

ofeyofey

unread,
Jan 16, 2016, 6:56:44 PM1/16/16
to Django users
hi,

I see the error there was dateTimeField.... and corrected that but now I get

pi@raspberrypi ~/DjangoPi/mathGenerator $ python manage.py migrate

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/pi/DjangoPi/mathGenerator/generator/models.py", line 8, in <module>
    class Choice(models.model):
AttributeError: 'module' object has no attribute 'model'

Thanks,


On Saturday, 16 January 2016 21:27:31 UTC, ofeyofey wrote:

Andrew Farrell

unread,
Jan 17, 2016, 1:04:41 AM1/17/16
to django...@googlegroups.com
you want 

class Choice(models.Model):

Note the capitalization of Model.
By convention, class names in python should be capitalized.

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

ofeyofey

unread,
Jan 17, 2016, 5:48:44 AM1/17/16
to Django users
Hi Andrew,
Wow MIT cool!
Thanks for looking at that. I corrected it and ForeignKey which was spelt wrong.
All working now.
I can move on with this tutorial.
Thanks again,


On Saturday, 16 January 2016 21:27:31 UTC, ofeyofey wrote:
Reply all
Reply to author
Forward
0 new messages