Django 1.4 not recognizing my app - django

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?

Related

Cannot use module aioflask(Python). ImportError: cannot import name '_app_ctx_stack' from 'flask.ctx'

I need to use aioflask for seting webhooks for my telegram-bot. Here my code, where I set webhook:
from aioflask import Flask, request
...
app = Flask(__name__)
...
#app.route('/')
async def webhook():
await bot.delete_webhook()
await bot.set_webhook(url=APP_URL)
return '!', 200
...
But, when I run app, it give me this error:
Traceback (most recent call last):
File "D:/Python_Projects/FilmMarketBot/check.py", line 1, in <module>
from aioflask import Flask, request
File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\__init__.py", line 2, in <module>
from .app import Flask
File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\app.py", line 14, in <module>
from .ctx import AppContext, RequestContext
File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\ctx.py", line 4, in <module>
from flask.ctx import AppContext as OriginalAppContext, \
ImportError: cannot import name '_app_ctx_stack' from 'flask.ctx' (D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\flask\ctx.py)
Please, tell how can I fix it. ...Why always me?
There seems to be a breaking change in Flask 2.2.0, which causes this incompatibility. As a workaround you can downgrade your Flask package to 2.1.3. This change solved the issue for me.
Reported the issue on GitHub: https://github.com/miguelgrinberg/aioflask/issues/10

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

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

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 on Pycharm: ImproperlyConfigured with DJANGO_SETTINGS_MODULE

I am trying to use Pycharm Community Edition to improve on my code in my Django application, but I cannot run all of my Django code that I'd like. I keep getting this traceback...
Traceback (most recent call last):
File "C:/Users/Jaysp_000/firstSite/PROJECTone/blog_static/views.py", line 1, in <module>
from django.views.decorators.csrf import csrf_exempt
File "C:\Python34\lib\site-packages\django\views\decorators\csrf.py", line 3, in <module>
from django.middleware.csrf import CsrfViewMiddleware, get_token
File "C:\Python34\lib\site-packages\django\middleware\csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python34\lib\site-packages\django\utils\cache.py", line 26, in <module>
from django.core.cache import caches
File "C:\Python34\lib\site-packages\django\core\cache\__init__.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
This error seems to involve the django.views.decortors.csrf.csrf_exempt that I imported to my views.py file. I've tried other files, and they have given me no issues. There is something in particular about this import, but I don't know what.
from django.views.decortors.csrf import csrf_exempt
#csrf_exempt
def handle_hook(request):
from django.http import HttpResponse
from django.core.management import call_command
result = call_command('update_blog', verbosity = 0)
return HttpResponse(result)
The same kind of issue shows up when I am trying to run the code on the python shell (I use 3.4) and when I import django.http.request as request. I type in handle_hook(request), and I get the same kind of error.
Im being told that I must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings, but I haven't a clue on how to do that. I've looked around and I am not certain if those methods specifically speak to my issue. Any clues?
Go to the Run Menu, select Edit Configurations..., then select the run configuration for you tests.
Select the environment variables button. You'll see one existing variable, which is PYTHONUNBUFFERED
Under that add (for example) DJANGO_SETTINGS_MODULE=mysitename.settings

ImproperlyConfigured: Error importing middleware app.middleware: "cannot import name get_host"

I've just upgraded to Django 1.5, and when I try and access a page, I get the following error:
ImproperlyConfigured: Error importing middleware app.middleware: "cannot import name get_host"
In the shell, I try a similar thing:
>>> from app import middleware
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../middleware.py", line 2, in <module>
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect, get_host
ImportError: cannot import name get_host
It's failing on the import of get_host. It doesn't seem that this is deprecated, what's going on?
In Django 1.5 django.http.get_host() is replaced with request.get_host(). See the methods on HttpRequest object here.