Django-dilla "Unknown command: 'dilla'" - python

I'm unable to make django-dilla work with my django1.4 project. I've installed django-dilla through pip and I can import it properly from shell.
>>import dilla
>>dilla.__file__
'/Users/misterte/.envs/python2.7-Django1.4/lib/python2.7/site-packages/django_dilla-0.2beta-py2.7.egg/dilla/__init__.py'
I've added it to my installed apps just before south, and ran my syncdb command.
INSTALLED_APPS = (
[...]
'dilla',
'south',
)
But when I try to call it, it won't work.
$python manage.py dilla --cycles=30
Unknown command: 'dilla'
Type 'manage.py help' for usage.
$python manage.py run_dilla --cycles=30
Unknown command: 'run_dilla'
Type 'manage.py help' for usage.
Then, of course, no sub commands are present under the [dilla] app when running help.
$python manage.py help | grep dilla
# emptiness :(
Any clues? Does dilla work in the django1.4 layout?
Thanks!
A.

So I found the problem.
For some reason pip is not installing dilla under site packages. I can import dilla and the egg is present under my site-packages folder, but further inspection showed that there were no packages under dilla.
Solution: copy dilla into you folder manually. I downloaded it from github.
Also, I recommend you copy it to a 'vendor' subfolder in your project. This way you avoid probably having to do the same hack in your production server. Then you import app as 'vendor.dilla' in your installed apps.
A.

Related

Django loops infinitly after startapp method call

I'm doing the CS50Web course, and there is a Django project in which I want to create a new app called "wikipedia". The problem is that after I run this command in Windows PowerShell:
python manage.py runserver
this loop happens:
loop print
I don't know what I did wrong for that to happen. After running
python manage.py startapp wikipedia
, I:
went to my Django project and added 'wikipedia' in the installed apps in settings.py
went to urls.py and added a path like this:
path("wiki/", include("wikipedia.urls))
And then I tried running the server. What did I do wrong?
You must have something improperly configured.
Run this:
$ pip uninstall django
$ pip install django
$ django-admin startproject <projectname>
$ cd <projectname>
$ django-admin startapp wikipedia
$ python manage.py makemigrations
$ python manage.py migrate
do what you described in your question
Also, it is always a better idea to run these things in the CMD, rather than in the PowerShell
Are you sure you have url mappings in your wikipedia app urls.py? Not having any patterns there could be the cause of an error.

Django manage.py runserver invalid syntax

I am developing a web in Ubuntu using django. Everything works normal. Now, I want to change my computer which use Windows. When I try to runserver, it gives:
E:\DEGNet>py manage.py runserver
File "manage.py", line 14
) from exc
^
SyntaxError: invalid syntax
E:\DEGNet>py
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
As shown above, I have installed Python 3.6.3. I have installed django and other necessary library using pip3 too.
Edit: manage.py file, it is a default manage.py that I get when generating the project.
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DEGNet.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
I faced same problem but now solved with this cmd:
python3 manage.py runserver
Edit your manage.py file as given below:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DEGNet.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
execute_from_command_line(sys.argv)
Note that from exc is removed from the file. It is not required in the manage.py file.
Make sure that your virtualenv is activated. Suppose the name of your virtualenv is pythonpy, then run these commands:
virtualenv pythonpy
workon pythonpy #After running these command, you should see something like this but your file path may be different: "(pythonpy) C:\Users\ MyDjangoProject \
Then go to the project folder which contains manage.py
(pythonpy) C:\Users\ MyDjangoProject \ #Same path as above
Then simple run the server:
python manage.py runserver #This will give you the project path to the localhost. Copy and paste the URL in the browser and should work.
Try (from command line):
python3 manage.py runserver
If I used this (no python3) instead:
python manage.py runserver
the error persisted. This method allows you to not have to alter manage.py (so you can keep "from exc").
You just forgot to activate the virtual environment , do it like that :
source /home/adel/Dev/Python/DjangoProjects/myproject/venv/bin/activate
And than you can run the server :
python manage.py runserver
i've also got this error but solve it by installing pipenv first,
try run this first
pipenv shell django==2.1
then you should be able to run
python3 manage.py runserver
Ensure you're running the app from virtualenv i.e if you've created a virtualenv for your project, then activate the venv first.
me#debian:~/Desktop/webapp$source venv/bin/activate
(venv) me#debian:~/Desktop/webapp$python manage.py runserver
What's happening is that the wrong version of python is being used, which may not have all the dependencies in your virtualenv. I get this error when using sudo manage.py: using sudo changes the version of python which is being used to /usr/bin/python.
The problem is solved by specifying which version of python to use when using sudo:
sudo /path/to/my/env/bin/python manage.py makemigrations
I have met the same problem, and I find it strange because I have activated the virtualenvironment and set the python3, however, I meet this problem when I use this statement "python manage.py runserver".I use this statement often but I meet this only once, and I restart my virtualenvironment and it runs, hope you wil,too.
I was facing the same issue.
Activated venv & ran python manage.py runserver wasn't working.
I could see the venv was activated but still it wasn't working. Then tried python3 manage.py runserver which got rid of exc issue but now it wasnt detecting my installed libraries.
The change I made that broke it was renaming the base folder ( kind of same situation like OP base folder location was different now).
But wait, how does this impact anything?
A variable that stores a full path to venv inside venv/bin/activate is
now no longer valid.
Resolution:
deactivate venv if already running
open venv/bin/activate
search for VIRTUAL_ENV variable and rename as per the new folder changes made.
activate venv source venv/bin/activate
run python manage.py runserver
Tada, everything is back to normal and we can happily enjoy our lemonade.
I've got also the same issue with Python 3.4.4 and Django 2.0. I tried the last solution, nothing works (no need to delete that: from exc on the line 14).
Just run your server with:
python manage.py runserver
Instead of:
./manage.py runserver #or '.\manage.py runserver' for Windows
I have no problem running this way:
sudo ./**(your path)**/bin/python manage.py runserver
i had the same problem. I solved it by simply specifying the python version i.e type python3 manage.py runserver instead of python manage.py runserver
i re installed the v env
virtualenv venv --python=python3.7
i insttalled django
it worked
I had come out of my virtial environment.
I re-ran pipenv shell
Do this first on your command line where your Env folder is found:
source Env/bin/activate
Then now navigate to your project directory and do:
python manage.py runserver
It works!!
Just use python3 manage.py runserver instead python manage.py runserver

cannot open manage.py after installing django

I have a problem in setting up django.
My situation: I have Anaconda Python 2.7 in my Windows 8 computer. On the Anaconda command prompt window, I type: pip install django. This is successful.
Then I create a folder named "newproject". On the command prompt I went to the folder "newproject". Then django-admin.py startproject newproject. This is successful.
Then I run python manage.py runserver. It tells me
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I checked out udemy django installation guide and other guides on the net. I have even set up a virtual environment. But the main problem is always: can't open file 'manage.py'
You're not in the proper directory...In the case you described, you should have:
mkdir newproject (not sure why you're doing this...but we'll continue with it)
cd newproject
django-admin.py startproject newproject
cd newproject ← A key missing part from what you did. You need to change into the directory where manage.py resides. Verify it by using ls at the command prompt after switching into the directory.
python manage.py runserver
Use ls often, if you need, to double check where you are in the directory tree.
You are not in the correct directory. You need to do cd newproject and the execute your runserver command.
For me it was because the manage.py didn't get created and the problem was that:
In windows instead of typing "django-admin.py" just type "django-admin" and it will create the manage.py file
you need to change your directory to the directory of the project.
open your environment by typing activate environment_name
change the directory to the folder in which you want to create the
project by cd Folder_Name
then create your project by django-admin startproject
Project_Name
then change the directory to your project folder
if you also want to create an app then typepython manage.py
startapp App_name
to confirm if it works type python manage.py runserver, then
you should get a link in the terminal. copy and paste that link in
the browser and you should see a successful page.
The reason of this problem is because you're in the first project directory "parent directory", and you have to go to your project "newproject" that has the manage.py file.
The way to this is simple:
cd "name of your project", E.g. cd newproject
python manage.py runserver
You need to include a . after you create the project.
Eg: django-admin.py startproject newproject .
This will allow you to run python manage.py runserver from where you are.
That can happen because manage.py doesn't have permissions.
Check the existence of manage.py throughout newproject, If exist you can fix it with:
$cd newproject
$chmod +x manage.py
Finally, try to execute python manage.py runserver
I was having the same problem, when Windows 10 changed credentials, Docker lost the access to drives. The fix for this issue, I reset the credentials in docker-desktop > shared Drives > reset credentials at bottom.
can't open file 'manage.py': [Errno 2] No such file or directory"
here is the solution
step 1: command -> django-admin startproject project_name
step 2: command -> cd project_name
step 3: command -> python manage.py startapp app_name
try it may fix your problem
You should navigate to the inner directory where your manage.py resides. For example:
If you have created projectname as
Django-admin startproject loginapp
Step 1: Go to loginapp
Step 2: Click on it
Step 3: You will find another loginapp and manage.py folder inside that
Step 4: Use this rootpath commandprompt
Step 5: Enter py manage.py runserver
Now it will work
I ran into the same error seller. But this is what I discovered
1: open your terminal in your project environment
2: install Django using: pip install django (if you are on windows)
3: then create your Django project using : django-admin startproject newproject . (django-admin start-project followed by project name give a space and add period (.) )
So it goes like this
django-admin startproject new project .
The period/fullstop (.) At the end tells djando the area in which the file should be created which is inside the project file its self you are working on. After this is done you are free to go. You can now run your server and enjoy
Run server using: python manage.py runserver
Make sure to put a period at the end of your command e.g
Django-admin startproject new project .
The period at the end (.) will solve the problem
There could be invalid interpreter selected .Try selecting the proper interpreter

DJANGO_SETTINGS_MODULE is defined, project settings do import via `python manage.py `, yet django-pytest does not find the django settings

Synopsis of problem:
I want to use django-pytest to test my django scripts yet py.test complains that it cannot find DJANGO_MODULE_SETTINGS. I have followed the documentation of django-pytest for setting DJANGO_MODULE_SETTINGS. I am not getting the expected behavior from py.test.
I would like help troubleshooting this problem. Thank you in advance.
References—django-pytest documentation
Setting the DJANGO_SETTINGS_MODULE in virtualevn postactivate script:
In a new shell, the $DJANGO_SETTINGS_MODULE is not set.
I expect that the $DJANGO_SETTINGS_MODULE would be None. It
is.
In: echo $DJANGO_SETTINGS_MODULE
Out:
Contents of .virtualenv/browsing/bin/postactivate
As documented in the django-pytest documents, one may set
$DJANGO_SETTINGS_MODULE by exporting it in the postactivate
script for virutalenv.
export DJANGO_SETTINGS_MODULE=automated_browsing.settings
At terminal cli:
As expected, $DJANGO_SETTING_MODULE is defined.
# activate the virtualenv
In: workon browsing
In: echo $DJANGO_SETTINGS_MODULE
Out: automated_browsing.settings
As expected, the settings module is set as shown when the server runs:
# cd into django project
In: cd ../my_django/automated_browsing
# see if server runs
In: python manage.py runserver
Out: # output
Validating models...
0 errors found
September 02, 2014 - 10:45:35
Django version 1.6.6, using settings 'automated_browsing.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
In: ^C
As NOT expected, py.test cannot find it.
In: echo $DJANGO_SETTINGS_MODULE
Out: automated_browsing.settings
In: py.test tests/test_browser.py
Out: …
_pytest.config.UsageError: Could not import settings
'automated_browsing.settings'
(Is it on sys.path? Is there an import error in the settings file?)
No module named automated_browsing.settings
installed packages
Django==1.6.6
EasyProcess==0.1.6
PyVirtualDisplay==0.1.5
South==1.0
argparse==1.2.1
ipython==2.2.0
lxml==3.3.6
psycopg2==2.5.4
py==1.4.23
pytest-django==2.6.2
pytest==2.6.1
selenium==2.42.1
test-pkg==0.0
wsgiref==0.1.2
Had the same problem today. In the project/settings/ you have to create init.py . Like this django recognize the folder.
In my case I just typed __inti__.py which was wrong. I corrected inti.py --> init.py and it works fine.
Hope it helps.
V.
Inspired by this answer, I have solved my problem.
According to the django-pytest documentation for managing the python path:
By default, pytest-django tries to find Django projects by
automatically looking for the project’s manage.py file and adding its
directory to the Python path.
I assumed that executing py.test tests/test_browser.py inside of the django project containing manage.py would handle the PYTHONPATH. This was an incorrect assumption in my situation.
I added the following to .virtualenv/$PROJECT/bin/postactivate:
export PYTHONPATH=$PYTHONPATH:$HOME/development/my_python/my_django/automated_browsing
And now py.test works as expected.

How to install django-cron on windows machine?

I'm trying to get django-cron to work on a winXP machine. (Wish I could use *nix).
Done
pip install django-cron
Added django_cron to INSTALLED_APPS in settings.py.
Then from windows console, ran below command
python manage.py syncdb
The result I got is:
"Not synced (use migrations):
`- django_cron`
(use ./manage.py migrate to migrate these)"
OK, So as per instructions from error msg I did, C:\ python manage.py migrate. Result is as follow:
Running migrations for django_cron:
- Nothing to migrate.
- Loading initial data for django_cron.
Installed 0 object(s) from 0 fixture(s)
Now what? What should I Google in order to figure out what's wrong with the migration?
Did I installed django-cron on the appropriate location?
Right now it's in
python27\Lib\site-packages\django_cron

Categories

Resources