Python Django: models in root giving error
Iam newbie to Python and Django. I have following "models.py" file .
from django.db import models
from django.contrib.auth.models import User
class Greeting(models.Model):
author = models.ForeignKey(User, null=True, blank=True)
content = models.TextField()
date = mode开发者_如何学JAVAls.DateTimeField(auto_now_add=True)
1- When I run following command:
from models import Greeting
It gives following error:
IndexError: list index out of range
But when i run above
from guestbook.models import Greeting
it gives no error.
Can some one guide me how can I run "models.py" file (without any error), which exists in root folder(not in "guestbook" application folder)
Thanks in advance
You shouldn't. You are fighting the basic project/application model of Django which underlies the entire system. You will continue to have nothing but problems and issues if you continue down this path.
Create an application and put the models.py in that application's subdirectory.
Edit: I don't mean to sound too harsh but one of the most important things I've learned about Django and Rails is "Don't fight the system".
精彩评论