I have a python file called
my_functions.py in which I have the following code:
from core.models import Blog def news(): b = Blog(name='New Blog', tagline='All the latest news.') b.save()
My main app folder in django is called core and I have put my python file in there. In the shell I am able to do the import:
from core import my_functions
However I get an error
AttributeError: module 'core.my_functions' has no attribute 'news' when I try to run the code
How can I run the
news function in the shell?
My tree structure is as follows:
core -__init__.py -admin.py -apps.py -models.py -my_functions.py -tests.py -urls.py -views.py
Everthing else works as normal but I just cant seem to figure why I cant do this simple import and run the function. I'm using VSCode.
Make sure there's an
__init__.py file in the
core directory. Then:
from core.my_functions import news
Also you have to restart your shell if you make changes to any file in your project, since the django shell will load all modules in memory at launch time.
- interaction of time.sleep with threading.Lock
- Python os.path.join() on a list
- How to get numbers after decimal point?
- how to subquery in queryset in django?
- Unable to run django custom command
- How to create a Function in python for detecting missing value?
- Jupyter notebook Memory limit
- Python code to convert from objectSid to SID representation
- Whoosh - accessing search_page result items throws ReaderClosed exception
- Fix Error converting data type varchar to numeric. (8114) (SQLExecDirectW)')
- categories = ("python", "django") Hard-coded list
- earn, Node, PHP, Python, django, lamp, server-side, servers
- of Python at https://www.python.org/downloads/ or with your
- ur machine go to https://python.org/downloads/. The website
- Programmers page on the python.org wiki). Guides Django
- $ python manage.py shell
- ip install closure $ python django/contrib/admin/bin/com
- _` method and apply the `python_2_unicode_compatible()` deco
- e page only path/to/python/file.py:123 msgid "Welco
- can use `manage.py` or `python -m django` just as well. U