I'm an old-school developer, learning Django and GitHub for the first time. I'd like to study https://github.com/tomwalker/django_quiz, but when installed in my virtual environment, I can't find the file "manage.py". A YouTube Django tutorial suggested I need to run "py manage.py runserver" to start a web server on my local machine. (I was successful starting a server when following THAT tutorial, but I'm now studying source code from GitHub.) There's clearly a difference in age between the sample project on GitHub and my YT tutorial... Can someone please tell me if I'm going about the learning of Django correctly, and if I truly need manage.py to start a server? Thank you!
This is an installable app, not a full project. As the instructions show, you should create your own project with django-admin.py startproject, then install this app and add it to the INSTALLED_APPS setting.
Note, this looks like a pretty old library and may not be compatible with recent Django versions.
Related
Background
I have a free account at pythonanywhere.com. My thanks to them for providing this very nice free service and learning experience.
To the PythonAnywhere folks who encourage me to use StackOverflow for questions about their site, I'll first say that I really like what you all have done with that site, and I'm excited to start building something there myself.
I've already done the first tutorial within pythonanywhere.com with Flask and a second simple webapp (that I adapted from your first tutorial) exactly the same but using your built-in django 2.2 in place of Flask.
Now I'm trying a tutorial from another site using python 3.8 and django 3.1.
I'm following along in Chapter 2 of the djangoforbeginners.com site (helloworld app) and trying to implement instructions there in my pythonanywhere.com account. I know I need to adapt some of the djangoforbeginners.com instructions to fit the pythonanywhere.com environment (e.g. pipenv didn't work, but pip install django~=3.1.0 did work).
(This is not my main question, but an example of the problems I expect to encounter adapting a tutorial from another site to the pythonanywhere.com environment) I encountered a problem with the python manage.py runserver step:
When I run the code above, I see the following error at the bash console:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 13, 2020 - 20:33:32
Django version 3.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.
And that makes sense to me because when I try to visit my webapp at username.pythonanywhere.com, I see a "Coming soon" page (after disabling my webapp in the dashboard; with my webapp enabled in the dashboard Web tab, I see a default "Hello World" page) which I know in both cases means that port is indeed already in use (by the server provided by pythonanywhere.com). So thinking about it a bit after seeing that error, I now think I should not even have attempted this python manage.py runserver step in the pythonanywhere.com environment. Duh! ;)
So moving on to my real question:
I've already followed instructions I found at https://help.pythonanywhere.com/pages/Virtualenvs including the part at the end where it reads: "Now that you have a virtualenv, and you know its path, you can go and enter it back in the Web tab.
Go to the Virtualenv section, and enter the path: /home/myusername/.virtualenvs/myvirtualenv"
I created my virtual environment using mkvirtualenv virtualenv01py38 --python=/usr/bin/python3.8 in pythonanywhere.com's bash console.
I also added to the Web tab in pythonanywhere.com's dashboard my source code directory for this web app: /home/username/projects/djangoforbeginners.com/ch02helloworld
When I used the dashboard Web tab to reload the web app, I saw this error message: "Your webapp took a long time to reload. It probably reloaded, but we were unable to check it."
But instead of the familiar Django welcome page, when I visit my webapp's URL, I see an apparently static html page:
"Hello, World!
This is the default welcome page for a PythonAnywhere hosted web application..."
So my question in general is how to implement the helloworld app from djangoforbeginners.com within the pythonanywhere.com environment?
And more specifically for now, my question is why I'm not seeing the familiar Django welcome page shown at djangoforbeginners.com in the first image, and how to continue to move forward past the python manage.py runserver step when I am apparently seeing pythonanywhere.com serve up its default hello world webapp (apparently just a static html page) instead of the django 3.1 hello world app that I'm trying to get it to serve up from the djangoforbeginners.com tutorial?
Thanks in advance for any suggestions.
You cannot run your Django web site from a console. You will need to use a web app if you'd like it to be available. We have a help page that describes in detail how to run an existing Django project as a web app.
Like Glenn said you would have to create a Web App under the Web tab first. I wrote an article How to deploy Django to Pythonanywhere that walks you through the whole process from GitHub, HTTPS, MySQL, and Environment Variable.
I followed a Django tutorial and the tutor didn't talk about the need for a Virtual Env. He deployed via Digital Ocean. I am trying to use Heroku but just found out that I ought to have activated a Virtual Env prior to the start of my Django project.
Do I have to redo the Django project with a Vir Env or I can just go ahead to activate the Env and still deploy?
Yes i think you can, but having a virtual environment is good practise. :) sorry if i wrong i'm new to all this.
The answer to your question is probably "you can still deploy" - however this depends on what tutorial you are following and what you want to archive, and cannot be answered without more information on your project. I suggest you simply try.
If you follow a tutorial that hosts a VPS webserver (e.g. from digitalocean), the necessary steps are different than if you deploy to heroku, obviously.
Read this official heroku/django guide to understand the deployment process. It is very useful and comes with a step-by-step guide for deploying python apps on heroku as well.
As virtual environments are (only) a fancy way of encapsulating python projects and their dependencies, this is exactly what you should read (to understand the basics and important details for future deploys of all kind of python apps to heroku).
Happy coding .
So I've been tasked with upgrading a Django server from 1.6.2 to the latest (~1.8), along with upgrading Python from 2.7.3 to 3.3. I suspect this is going to break quite a bit of code. (I even need to upgrade the Ubuntu installation from 12.04 to 14.04)
I would like to migrate my Django app from the server it's currently running on (Ubuntu 12.04) to a virtual machine, and use that environment as a sandbox to make changes.
Would anyone be so kind to provide guidance on django app migration? Please let me know if you'd like me to provide any specific details.
Thank you.
Edit: If anyone would like to vote down this question because they believe I haven't done enough research, I'm very happy to add missing information, if I know what you're looking for.
Django versions from 1.5 onwards has been designed so that the same code will work on both versions of Python as in the documentation thanks to them following the six compatibility layer.
You might face some issues with code that isn't strictly related to Django components like print statements and other such parts that might have been coded in. The official Python Porting Guide should held you with that.
Django 1.8 is a LTS (Long Term Release) so it's a good idea to upgrade to it. Migrating the database might be a bit of an issue considering it's from 2.7 to 3.4 but that's in all likelihood the place you'll find most issue with. The How to Migrate is a great resource.
If I recall correctly the directory structure is a bit different in 1.6 so you'll have to move some code and files manually. I suggest having the tutorial pages for both versions 1.6 and 1.8 open and comparing the directory structure.
Going through the first 2 pages of the tutorial should give you enough of an overview to migrate the database and the settings file. This should also help with migrations.
The 3rd and 4th pages should get you through migrating the views and urls files.
The only thing I'm not familiar with is the migration of the wsgi file which has configuration information, you should be able to find some basic information about that here.
Updating your Ubuntu however won't change or affect anything at all.
Also as has been said in the comments by jape and joel, it's a good idea to use virtualenv and git.
I would like to add another suggestion based on my own experience with pushing code to a Django server :
Download the code base to your local machine and work there and once you're done and the server is working well on your machine push it all to the server at once. That way you can isolate server machine specific issues from coding issues.
So I got advice in another question and they started talking about paths and .exe and that I should not put my projects in the scripts. So I added
C:python27\scripts to my path and nothing seemed to change except when I created a new project, and went into the GUI to look for the folder and found it, it just says Manage instead of manage.py. It says its a python folder.
I then took ..\scripts out of the path and created the project again and still got the same thing.
Whenever I did it the first time without changing anything, I did see a manage.py file.
So the tutorial I am working that introduces me to Django asked me to open the manage.py file, and when I try to of course it tells me it can't open the file because it does exist. So what do I do?
If I'm understanding you correctly, you're simply trying to create a django project. Since you didn't mention which tutorial you're using, I'll link this resource and recommend following it page for page. It's a great walk-through for learning how to create apps and it's broken into sessions you can do over a period of time:
To answer your question: when you create a django project with django-admin startproject mysite it will install the manage.py into the mysite directory. If that doesn't answer your question, try describing the precise steps you're taking to create a Django project including all commands you're using (if any).
It's also helpful to know if you're using a virtual environment.
Finally made the switch from Windows to Linux (Ubuntu). I am teaching myself Python + Django.
GOAL: I want to setup a local development environment where I can build a django application and run it locally before deploying it live online.
SO FAR: Python comes installed with Linux. Gedit does also. Ok great. After that I am lost.
I am not sure how to proceed. I am a total Linux noob. I am guessing I need apache running, mysql running, and django to run. I don't know how to setup these things to run or how to set the proper directories or what I need to link to what... really I am not even sure what the right questions are to ask.
Quick answer:
Just install django via their documentation, and you will not even need apache running as it will run its own server. You can use sqlite as a db and you won't even have to worry about mysql. This is if your goal is to learn django and get things running asap.
Otherwise, if you want to take the full route, you'll need to start learning a lot more (which isn't a bad thing). I'd say take a look at some of the slicehost guides for setting up apache, mysql in ubuntu:
http://articles.slicehost.com/2010/5/19/installing-apache-on-ubuntu
http://articles.slicehost.com/2011/3/10/installing-mysql-server-on-ubuntu
And then pick up with just installing django and going from there. The django tutorial is awesome. There's plenty of other documentation out there on the web & tutorials for setting up dev environments.
Assuming you have python
You can install pip:
easy_install pip
From now you can use pip to install your python libraries for example to install django
pip install django
For development I would prefer pydev, it has a support for django with the power of eclipse.