What does it mean attempted relative import beyond top-level package? - django

Traceback
File "", line 5, in <module>
from ..books.models import Commen
ImportError: attempted relative import beyond top-level package
forms.py
from ..books.models import Comment
Maybe problem in urls.py?
There is the structure of my project
enter image description here

Related

No module named 'django.contrib.admin.templatetags.admin_static'

my django version is 3.0.5 and django-suit version is 0.2.28 but why does this error happen?
the whole error information is as follows:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\admin.py", line 8, in <module>
from suit.widgets import NumberInput, SuitSplitDateTimeWidget
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\widgets.py", line 6, in <module>
from django.contrib.admin.templatetags.admin_static import static
ModuleNotFoundError: No module named 'django.contrib.admin.templatetags.admin_static'
I solved the problem.
Modify this fileļ¼š \Python38\Lib\site-packages\suit\widgets.py
# from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin import static
then rerun your program, maybe met problem below:
File "D:\Work_Station\Python38\lib\site-packages\suit\templatetags\suit_menu.py", line 17, in <module>
string_types = basestring,
NameError: name 'basestring' is not defined
modify the file : Python38\lib\site-packages\suit\templatetags\suit_menu.py
# from django.utils.six import string_types
from six import string_types

ModuleNotFoundError for model class in django

I ran into the following ModuleNotFoundError error.
File "C:\django-project\CodingWithMitchBlog\demoproject\Blog\api\urls.py", line 3, in <module>
from demoproject.Blog.api.views import api_detail_BlogPost_view
ModuleNotFoundError: No module named 'demoproject.Blog'
'Blog' is my appname.
This is my project structure.
This might be due to incorrect import statements used in the files. If the import statements has the projectname prefixed try removing it and run again.
For example change:
from demoproject.Blog.models import ModelClass
to
from Blog.models import ModelClass
in the urls.py file

ImportError: cannot import name routes

I am doing Miguel Grinberg's tutorial on Flask. I am having a strange issue: before, this wasn't happening, but now it is. When I try to run flask shell or simply run my application, I receive the following error:
NoAppException: While importing "app.microblog", an ImportError was raised:
Traceback (most recent call last):
File "c:\projects\blog\virtualenv\lib\site-packages\flask\cli.py", line 235, in locate_app
__import__(module_name)
File "c:\Projects\Blog\app\__init__.py", line 14, in <module>
from app import routes, models
File "app.py", line 11, in <module>
ImportError: cannot import name routes
I thought it might be a circular dependency problem, but that didn't seem to be the case. I've tried searching all over for the answre but can't seem to figure it out.
Thanks for your help.
It seems you are importing the routes from app module within app module.. If you can share some more snippet, that would be helpful in understanding the problem.
But it seems,
from app import routes, models
File "app.py", line 11, in <module>
ImportError: cannot import name routes
In these lines, it says the exception is occuring in from app import routes, models line which is line 11 of app.py file.
So you are just importing the app module within app module.
I think you shouldn't import like the way you do already. Instead use the following:
import app
...
...
...
#app.routes('/something', methods=['DESIRED_METHODS']
def your_function():
pass

Django 1.4 not recognizing my app

I am using django 1.4, and the app.module name does not seem to be working as expected for me. My settings.py has the app included as "survey.surveys".
Here is the django shell dump for an import I attempted through a preexisting file. The error says No module named ....
from survey.surveys.views.db import mobile_survey1
Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/pjain/dev/survey/survey/surveys/views/db.py", line 6, in <module>
from survey.surveys.models import Survey, Section, Question, Option
File "/home/pjain/dev/survey/survey/surveys/views/survey.py", line 7, in <module>
from survey.surveys.models import Survey, Section, Question, Option
ImportError: No module named surveys.models
However, when I copied and pasted the exact import which breaks, it imports fine in the shell.
from survey.surveys.models import Survey, Section, Question, Option
How can I fix this import in my project?

ImportError: No module named models

I am going a tad crazy here. I keep getting this error: ImportError: No module named models and I am not sure why. Here is what I have found so far...
>>> from django.shortcuts import get_object_or_404, redirect
>>> from mystore.cart import cart
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/Jeff/django/mystore/cart/cart.py", line 3, in <module>
from mystore.cart.models import CartItem
ImportError: No module named models
>>>
I am not sure what's going on with this... line 3 in cart.py is this:
from mystore.cart.models import CartItem
If I try to do: from mystore.cart.models import CartItem it works fine...
Any suggestions?
Almost certainly, you have a circular dependency: mystore.cart.cart is importing mystore.cart.models, which in turn is trying to import mystore.cart.cart.
You should determine if both of those imports are necessary, and if either of them could be moved out of the global scope into a function or method.
Why are you doing from mystore.cart import cart? That should be just from mystore import cart.
Very early in the mystore.cart.models an error is occurring that's why nothing in models.py can be imported. The error can be a circular import, a conditional statement that's triggered during runtime but not at the command prompt or is happening inside something else your are importing at the beginning of models.py
You have to put a point before.
bad
from models import *
good
from .models import *
that means that is at the same level.