Pythonanywhere - something went wrong - error running wsgi - modulenotfound error - django

I am new to django and I am doing a coursera course with little applications deployed on pythonanywhere, which has worked well so far. No I am stuck, because does not load at all. Pythonanywhere says that Something went wrong.
This is the error log from pythonanywhere.
Error running WSGI application
ModuleNotFoundError: No module named 'django_extensions'
This is my WSGI file
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()
This is my settings.py file, not the entire one but the installed apps:
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'ads.apps.AdsConfig',
# Extensions - installed with pip3 / requirements.txt
'django_extensions',
'crispy_forms',
'rest_framework',
'social_django',
'taggit',
'home.apps.HomeConfig',
]
This is my urls.py, not the entire one, but the crucial part.
import os
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.views.static import serve
urlpatterns = [
path('', include('home.urls')), # Change to ads.urls
path('ads/', include('ads.urls')),
path('admin/', admin.site.urls), # Keep
path('accounts/', include('django.contrib.auth.urls')), # Keep
# url(r'^oauth/', include('social_django.urls', namespace='social')), # Keep
]
I checked django version, requirements are installed. I double checked with pip list.
Running python3 manage.py check has no errors. I can do all mirgrations without errors. I don't know anymore where to look for the problem.
I already did 3 or 4 of these mini applications and I did not have this problem. wsgi points to mysite.settings and the settings.py has django_extensions as INSTALLES APPS.
What is the problem? Please help

There are multiple Python versions installed on PythonAnywhere. Make sure that you installed the required module for the same Python environment that your web app is being run by. For example, if your web app is set to be run by Python 3.8, check if you installed the module with pip3.8 django_extensions --user command; if you are using a virtual environment, make sure it's set on the Web page and that you installed the module inside of that venv.

Related

Django doesn't see urls.py

I'm new to Django and I'm following this tutorial: https://www.django-rest-framework.org/tutorial/1-serialization/
When I run the server with python manage.py runserver, it seems to work fine showing me no errors.
However when I visit http://127.0.0.1:8000/snippets/ it gives me the following error:
Using the URLconf defined in tutorial.urls, Django tried these URL patterns, in this order:
admin/
The current path, snippets/, didn’t match any of these.
Here's my urls.py located in the tutorial folder:
from django.urls import path, include
urlpatterns = [
path('', include('snippets.urls')),
]
I don't understand what's going on, how come it only checks admin/ if I'm wiring the root urlconf to snippets.urls?
On a related note, when I modify urls.py and add gibberish the server won't give me an error, however if I were to modify models.py then it'll start complaining, that's why I'm getting the feeling it doesn't even check my urls.py and maybe instead some default one...
Any tips are very appreciated!
EDIT:
Here's my urls.py located in the snippets folder:
from django.urls import path
from snippets import views
urlpatterns = [
path('snippets/', views.snippet_list),
path('snippets/<int:pk>/', views.snippet_detail),
]
In settings.py I've only modified the INSTALLED_APPS part with the two last apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'snippets.apps.SnippetsConfig',
]
Are you sure you don't have another instance of Django running?
That's the only thing I can think of since admin isn't even in your current urls

ModuleNotFoundError: No module named 'polls'

I am following the official Django tutorial on https://docs.djangoproject.com/en/2.2/intro/tutorial01/ but somehow I am not able to run the server as I have created the polls app and added the required urls. When I use the command "py mysite\manage.py runserver" it returns me ModuleNotFoundError: No module named 'polls' error.
Project Folder available at
https://i.stack.imgur.com/bbxfW.png
#views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('<h1><this is a test page</h1>')
#urls.py in polls
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
#urls.py in mysite\mysite
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
#settings.py
INSTALLED_APPS = [
'polls',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
[1]: https://i.stack.imgur.com/bbxfW.png
Well, I resolved it myself. Polls module was not found because it was created outside the project directory. When I removed it and recreated inside the project directory, it was OK now.
also it may be a good idea to cd into yoru django project so you are only running
python manage.py runserver

DoesNotExist at /admin/login/

DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: https://tehb123.pythonanywhere.com/admin/login/?next=/admin/
Django Version: 1.9.3
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /usr/local/lib/python3.5/dist-packages/django/db/models/query.py in get, line 387
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.5.1
Python Path:
['/var/www',
'.',
'',
'/home/tehb123/.local/lib/python3.5/site-packages',
'/var/www',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/tehb123/mysite']
Server time: Thu, 13 Oct 2016 05:34:55 +0000
urls
from django.conf.urls import url, patterns, include
from django.contrib import admin
from django.contrib.flatpages import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('Mysitez.urls')),
# url(r'^pages/', include('django.contrib.flatpages.urls')),
]
urlpatterns += [
url(r'^(?P<url>.*/)$', views.flatpage),
]
settings
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.templatetags',
'django.apps',
'django.contrib.sites',
'django.contrib.flatpages',
'Mysitez',
]
SITE_ID=1 in setting and all work, but why? not have idae =(
I found the solution in this other post:
"You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:
'django.contrib.sites'
"
The admin site
once you create the project with django version > 1.6 , the admin site will enable django itself. but make sure you have following ["https://docs.djangoproject.com/en/1.10/ref/contrib/admin/"], once you create project , make python manage.py migrate then create the admin user using (python manage.py createsuperuser ). do the run command see the url like ("http://127.0.0.1:8000/admin/") you can see the login page

Django Basics myapp mapping in myproject "myapp" is not defined

I am learning django, and have ran python manage.py startapp myapp which created the following folder structure:
myapp/
__init__.py
admin.py
models.py
tests.py
views.py
I also added myapp to INSTALLED_APPS in settings,
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
)
then I ran python manage.py migrate and python manage.py createsuperuser to create super user
I have also created views of myapp :
"from django.http import HttpResponse
def hello(request):
text = """<h1>welcome to my app !</h1>"""
return HttpResponse(text)
"
Finally, here's the URL mapping:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin', include(admin.site.urls)),
url(r'^hello/', 'myapp.views.hello', name = 'hello'),
)
When ran, it throws an error stating that "myapp" is not defined. And I am not able to access admin page at http://127.0.0.1:8000/admin
How can I solve this error and get my application to work?
Possibly myapp is not included in INSTALLED_APPS in setting.py. I suppose you are following this tutorial.
add this in your url mapping:
from myapp import views

dojango test install results in 404

I made a fresh install of django 1.6.2 in it's own virtualenv. No syncdb, no other configs. The only other apps installed are pip, setuptools and dojango. I followed the instructions in this wiki page https://github.com/klipstein/dojango/wiki/Gettingstarted
when I try 127.0.o.1:8000/dojango/test/ or localhost:8000/dojango/test I get
Page not found (404)
Request Method: GET
Request URL: http://127.0.o.1:8000/dojango/test/
Using the URLconf defined in dojango.urls, Django tried these URL patterns, in this order:
^dojango/ ^dojango/
The current URL, dojango/test/, didn't match any of these.
this is my INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dojo_tutor',
'dojango',)
and this is my urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^dojango/', include('dojango.urls')),
# url(r'^admin/', include(admin.site.urls)),
)
The wiki page says to use (r'^dojango/', include('dojango.urls')), but I tried both like that and url(r'^dojango/', include('dojango.urls')),. I still get 404
Ok, it was a silly mistake. Foolishly I had named my project dojango so naturally there was a naming conflict. Deleted the project and recreated it with another name. Now it works.