Forums

Using Visual Studio (not Visual Studio Code)

Prior to finding PythonAnywhere I began the Learn Django tutorial in Visual Studio. Note that it is not using Visual Studio Code. VS did most of the configuration for me; it has a test server and installed Django into it and everything. I have completed the first page of the tutorial and the website works locally. My GitHub repository is SimpleSamples/LearningDjango.

Then I discovered PythonAnywhere. I have cloned the repository into PythonAnywhere but I do not know if it can be used in PythonAnywhere.

It will be wonderful if I can use VS as my IDE to create and modify a Python Django website and upload (push?) to GitHub and then have it deployed to PythonAnywhere. Is that possible? I will likely choose a different IDE, perhaps Eclipse, in the new future but for now I want to continue with VS.

We do not yet support VS code for deploying and configuring web apps. We have a help page about how to deploy existing Django projects here: https://help.pythonanywhere.com/pages/DeployExistingDjangoProject/

I said not VS Code. Do you know what Visual Studio is? It is not Visual Studio Code. Visual Studio is the Microsoft IDE used by professional developers for more than 20 years. PythonAnywhere compatibility with Visual Studio could expand the potential customers for PythonAnywhere very much. Ignorance of that market significantly inhibits the growth of PythonAnywhere.

Sorry for the confusion there!

If you can push from Visual Studio to GitHub, then once you have your site up and running then you can do a deploy with a couple of steps -- it won't be a single-button deploy, but the process would be:

  • Push to GitHub from VS
  • Pull from GitHub from a Bash console inside PythonAnywhere
  • Reload the site from the "Web" page inside PythonAnywhere

So, three (short) steps instead of one click, but not too painful. (It would be theoretically possible to set things up using GitHub's actions framework to make it single-click, but I think that could be a bit error-prone.)

Regarding getting it all set up in the first place -- check out the link that @glenn gave earlier on, which should give you the details you need for how to get your cloned repository up and running. If you have problems with the steps described there, let us know and we should be able to help.

Wonderful. Thank you. As I said in my original question, (I think) I have already done the first two steps. I am not sure I did the reload after that. I have since moved on and I tried doing the Django tutorial (as discussed in my other question) and got stuck with it. I will attempt to switch back to the app from Visual Studio (pulled from GitHub). It will be exciting when I get it to work.

I do not know how I pulled the repository from GitHub (the repository is public) but I have this. When I set my web app to that directory (and reload) I just get the rocket.

enter image description here

It looks like your web app is not running the default django web app, not the code you want it to run. How does your /var/www/simplesamples_pythonanywhere_com_wsgi.py file look like?

Below the comments the /var/www/simplesamples_pythonanywhere_com_wsgi.py file has:

import os
import sys

path = os.path.expanduser('~/mysite')
if path not in sys.path:
    sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())

That will load up the site that is stored in the mysite subdirectory of your home directory, but from your screenshot above, you seem to have checked out the code into ~/LearningDjango/BasicProject, so that is what should go in place of mysite in your path variable. You would then need to replace the mysite in the DJANGO_SETTINGS_MODULE with the name of the directory inside that directory that contains your settings.py file.

I have progress. Now I am getting:

AttributeError at /
module 'django.contrib.auth.views' has no attribute 'login'
Request Method: GET
Request URL:    http://simplesamples.pythonanywhere.com/
Django Version: 3.2.6
Exception Type: AttributeError
Exception Value:    
module 'django.contrib.auth.views' has no attribute 'login'
Exception Location: /home/SimpleSamples/LearningDjango/BasicProject/BasicProject/urls.py, line 30, in <module>
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.7.10
Python Path:    
['/home/SimpleSamples/LearningDjango/BasicProject',
 '/var/www',
 '.',
 '',
 '/var/www',
 '/usr/local/lib/python37.zip',
 '/usr/local/lib/python3.7',
 '/usr/local/lib/python3.7/lib-dynload',
 '/home/SimpleSamples/.virtualenvs/django2/lib/python3.7/site-packages']

Plus much more diagnostic data. Perhaps there is an incompatibility of versions; the virtual environment might be wrong.

The Python environment that Visual Studio uses for that is this.

I uploaded the wrong file here so I deleted this post.

The error says there's an AttributeError -- you're trying to import login from django.contrib.auth.views whereas it should be imported from django.contrib.auth directly, see: https://docs.djangoproject.com/en/3.2/topics/auth/default/#how-to-log-a-user-in.