Issues with Django setup - python

I am using Python 3.4 and Django 1.8.
I can't seem to be able to start Django properly. Whenever I run django-admin.py startproject mysite it opens Sublime but it is missing the directories manage.py and all of the other .py files. mysite is just blank.
Any reason why? I have followed http://tutorial.djangogirls.org/en/django_start_project/README.html and so far had no problems until this.
EDIT: I fixed the problem, for some reason when I entered the command django-admin.py it would not work but when I removed the .py in the command it worked.

To me this doesn't sound like a Django problem. Since you do not mention with which OS you see this behaviour, I can only guess that you have an file type association that launches your code editor rather than the python executable.
For windows, anything ending in .py should be run by Python, not your editor. Other OSes are more sophisticated about file names and their associations.

Related

Pycharm can't find Django app 'users' when running tests

I was handed a project which uses Django and Docker, but when I run Django tests Pycharm always seems to have problem finding the users application. Other people in the project have it running without problems but even though we tried to copy their settings, it wouldn't work. I also downgraded to their exact Pycharm version without success. What could be wrong?
I have Docker desktop running without any problem. It's able to create containers and all that. I've also included it in Pycharm with success.
I've also created an interpreter through Docker-compose with a valid .yml file. This file is my colleagues.
I've of course added it as my project interpreter.
I've set up a Django test configuration with appropriate interpreter and with an empty target field so that all applications in INSTALLED_APPS are run, as per documentation.
Still, the module 'users' cannot be found. Passing in DJANGO_SETTINGS_MODULE=config.settings.local to the test configuration yields the same error.
However, when I run from the terminal, all works as expected.
What might be the problem here?
I was using the modern django setup (generated from cookiecutter-django) which Pycharm seems to have trouble with. By right-clicking the folder and choosing "Mark directory as" and marking my project directory as "Sources Root" (i.e. the project/project folder), Pycharm was able to run it properly.
Did you try unchecking options related to PYTHONPATH in your run configuration?
It may override your modules path and cause such mess with finding them.

django-admin.py startproject mysite is not doing anything

It worked when I did the poll tutorial in linux, but I'm doing it again in Windows 7, and it does nothing.
I already set the environmental variables, and set the file association to my python27.exe
When I run django-admin.py startproject mysite from the DOS command prompt, it executes, but it's showing me all the information (Like the options, etc) as though I typed the help option instead. It's not actually creating project files in my directory. I appreciate the help.
also, I tried the solution found here (it appears to be the exact same problem).
It did not work
django-admin.py is not working properly
I ran into the same problem.
Never having worked with Django before but having worked with Python 2.7 a fair bit, all on a windows 7 platform. I downloaded the latest version of Django and unpacked it on my desktop.
After mucking around a bit managed to get it to install itself. I found could not just follow the tutorial thats provided in the docs googled the problem and found this thread, now I was able to get it to work by doing the following things,
I work with a dos command window open. I navigate to the root of where I want the project file to be set up. I then ensure that the django_admin file has been editted as per wynston's instructions and then typed the following.
python c:\location of django_admin.py startproject projectname
and it executed beautifully.
*Thanks to wynston for the edit to the django_admin.py file.
Try to run python27 django-admin.py startproject mysite from the command line,maybe a different (older) python.exe executes the django-admin.py file. If there's a program associated to the .py files, things mixes up, and your path environment variable doesn't matter.
I suggest you to use virtualenv. When you use it, you should put the python.exe before every .py file you want to run, because the install of python will associate .py files to the installed python.exe, and will use that, whatever is in your path. :(
Change the first line of django-admin.py #!/usr/bin/env python to for example
#!D:\Program Files\Python\python.exe (Where you install your python.exe,that's my directory), it works.
Use python django-admin.py startproject mysite. That worked for me some time ago when I had the same issue.
The solution is simple in Windows:
1-Go to C: \ Python34 \ Scripts
2-Right click on django-admin.py
3-Select open with
4-Select default program
5-Select Laucher Python for Windows (Console)
6- Run the command in CMD Windows python django-admin.py startproject mysite
Great answers. But unfortunately it did not work for me. This is how I solved it
Opened django_admin.py as #wynston said. But the path at first line was already showing #!C:\ correctly. So did not had to change it
I had to put "..." around django-admin.py address. Navigated to the project directory in cmd.exe and ran this
python "C:\Users\ ......\Scripts\django-admin.py" startproject projectname
It worked only with the quotation marks. I am using Anaconda Python 2.7 64 bit, on Windows 7, 64 bit. Hope it helps

Django Error: Could not import settings 'interfaces.settings'

So, I'm fairly new to programming. I have relatively little background in django and don't understand much of its implementation. However I have read through django tutorials and have a basic understanding of the underlying structure.
So currently I am not actually modifying the django project being used by the server (lets call it /main), I think my coworker copied over the project to a new directory called /test. When I try to do anything with manage.py located in the /test directory by running
python2.4 manage.py runserver
I get an error saying
Django Error: Could not import settings 'interfaces.settings'
(Is it on sys.path? Does it have syntax errors?): No module named settings.
I've looked through the settings file and have tried changing main to test, but it hasn't changed anything.
Any guidance as to where I should look for a solution would be great.
Also?
It sounds like there is something hard-coded somewhere which expects the project to be in a directory called "interfaces", rather than "test". Try running manage.py shell --settings=settings, and see if that helps.
Actually, "also", you should not be editing code on the server, even if it's in a different directory to the production deployment. Install Django and the code on your local machine, and edit there.
The manage.py shell --settings=settings worked for me. I figured out from running django-admin.py runserver that settings could not be imported, because environment variable DJANGO_SETTINGS_MODULE was undefined.
Fix: export DJANGO_SETTINGS_MODULE=settings
I ran the command from the root of the project (same directory that had manage.py -- not sure if it matters). Then, running manage.py shell worked without the --settings=settings bit.
Cheers!
Try to undestand which versions of python you have installed.
Type python2 and press tab button in console.
It looks, that you are trying to run version of python, which has not django installed in libs.
Also try to run python2.4 in interactive mode from test folder and import settings.

Why does django open with pype?

when i type in the command prompt
django-admin.py startproject mysite
the django-admin.py will open automatically with pype,
now if i type cd mysite it says the system cannot find the path specified
I'm using activepython (i don't think that activepython has anything to do with it), django installed using pypm. I can create a project in pydev, not in the command prompt, about a year ago when i first installed activepython, it used to work but as far as i can remember i deleted a django project and it won't work anymore.
how to fix it?
EDIT
#Mikko Ohtamaa
mysite folder does not exist,i see on pype that it has opened the file from C:\Documents and Settings\Administrator\Application Data\Python\Scripts\django-admin.py
but the path is incorrect i don't have an application data folder in C:\Documents and Settings\Administrator\
I have searched the entire pc and haven't find a folder, furthermore in you run this 100 times
django-admin.py startproject mysite
it will keep opening a file called django-admin.py you know, nothing else
"but the path is incorrect i don't have an application data folder in C:\Documents and Settings\Administrator\"
This would mean that your Python or Django installation is corrupted (probably due to reinstall Python).
Try go to square zero and reinstall both Python and Djangon on your computer. Also if it still does not work please describe how did you install both of them.

How to make Python knows the path to look for .py files?

Just started trying to learn Python and Django today. Following their documentations I was able to install Python and Django and got them up and running. I'm running Apache 2.2 on on Windows 7 by the way.
I got to the part in the official tutorial that tells me to cd to the directory I want for my project and run this command
django-admin.py startproject mysite
However I can't just run that command as is. I need to run it like this
python c:\Python27\Scripts\django-admin.py startproject mysite
Am I suppose to type out the whole thing like this? Or is there some settings I miss that will let me run the .py file without the python C:\Python27\Scripts\ part in front?
If you want to just be able to type django-admin.py, two things need to be set up:
The directory containing it needs to be in your PATH.
You need to make sure that the .py extension is associated with the Python interpreter. This is normally done during the installation of Python.
How to set the PATH on Windows 7: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx
How to make sure .py is associated with Python: http://docs.python.org/faq/windows.html
Try running:
python django-admin.py startproject mysite
If that don't work, try adding C:\Python27\ to the command search path

Categories

Resources