Python Forum
module object has no attribute after using different version of Python
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
module object has no attribute after using different version of Python
#1
I have both versions python 2.7 and 3.4 installed. I am using some code which is developed under 2.7 but I am using under 3.4. So after compiling using the following command

python manage.py runserver
I get the following error -

File "C:\pyprojects\focus\site\general\forms.py", line 26, in Meta
model = models.UserProfile
AttributeError: 'module' object has no attribute 'UserProfile'

As models.py and forms.py is under same directory(general) so I have imported the model in forms.py in this way
from .models import models
Now in models.py I have defined the class

class UserProfile(models.Model, HashedPk):
        user = models.OneToOneField(User, unique=True)
        is_pro = models.BooleanField(default=False, blank=True)
        ......................................................
In forms.py the code is

class UserProfileForm(forms.ModelForm):
    class Meta:
        model = models.UserProfile
        .....................
Is there any special way to call the model in python 3.4.

Any help is highly appreciated.
Reply
#2
Instead of from .models import models, why not from . import models?
Reply
#3
Just brilliant. You have saved my life and a day. Many thanks for helping me out. I am new in python but loving it more than anything and learning every day every minute.

Thanks once again. I will make this thread solved.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,446 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  type object 'man' has no attribute 'centerX' Tempo 7 873 Mar-07-2025, 03:47 AM
Last Post: deanhystad
  module 'openpyxl.workbook' has no attribute 'active' lsaavedra21 5 1,729 Oct-30-2024, 06:26 PM
Last Post: lsaavedra21
  How to find out from outside Python (in Windows) the current version of Python? pstein 5 2,342 Jun-28-2024, 07:02 AM
Last Post: Samuel34
  run part of a script with a different version of Python jdog 3 2,420 May-27-2024, 01:57 AM
Last Post: Alice12
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 2,839 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 6,042 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 7,219 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 1,879 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  How to resolve version conflicts in Python? taeefnajib 0 2,149 Apr-27-2023, 08:37 PM
Last Post: taeefnajib

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020