Forums

error when running the web app of djangogirls at pythonanywhere.

I follow the tuttorial of djangogirls and I am at the point where I want to setup the web app at pythonanywhere. I give the command: " pa_autoconfigure_django.py --python=3.6 --nuke https://github.com/avraam1616/my-first-blog.git ", copy paste from the tuttorial. I receive the following error message: < Running API sanity checks > \ ~<:>>>>>>>>> Cloning into '/home/avraam57/avraam57.pythonanywhere.com'... remote: Enumerating objects: 42, done. remote: Counting objects: 100% (42/42), done. remote: Compressing objects: 100% (24/24), done. remote: Total 42 (delta 13), reused 42 (delta 13), pack-reused 0 Unpacking objects: 100% (42/42), done. Checking connectivity... done.

< Creating virtualenv with Python3.6 > \ ~<:>>>>>>>>> Removing avraam57.pythonanywhere.com... Running virtualenv with interpreter /usr/bin/python3.6 Already using interpreter /usr/bin/python3.6 Using base prefix '/usr' New python executable in /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/python3.6 Also creating executable in /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/python Installing setuptools, pip, wheel... done. virtualenvwrapper.user_scripts creating /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/predeactivate virtualenvwrapper.user_scripts creating /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/postdeactivate virtualenvwrapper.user_scripts creating /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/preactivate virtualenvwrapper.user_scripts creating /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/postactivate virtualenvwrapper.user_scripts creating /home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/get_env_details

< Pip installing django (this may take a couple of minutes) > \ ~<:>>>>>>>>> Looking in links: /usr/share/pip-wheels Collecting django Using cached Django-3.1.1-py3-none-any.whl (7.8 MB) Collecting pytz Using cached pytz-2020.1-py2.py3-none-any.whl (510 kB) Collecting sqlparse>=0.2.2 Using cached sqlparse-0.3.1-py2.py3-none-any.whl (40 kB) Collecting asgiref~=3.2.10 Using cached asgiref-3.2.10-py3-none-any.whl (19 kB) Installing collected packages: pytz, sqlparse, asgiref, django Successfully installed asgiref-3.2.10 django-3.1.1 pytz-2020.1 sqlparse-0.3.1

< Creating web app via API > \ ~<:>>>>>>>>>

< Adding static files mappings for /static/ and /media/ > \ ~<:>>>>>>>>>

< Updating wsgi file at /var/www/avraam57_pythonanywhere_com_wsgi.py > \ ~<:>>>>>>>>>

< Updating settings.py > \ ~<:>>>>>>>>>

< Running collectstatic > \ ~<:>>>>>>>>> Traceback (most recent call last): File "/home/avraam57/avraam57.pythonanywhere.com/manage.py", line 22, in <module> main() File "/home/avraam57/avraam57.pythonanywhere.com/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/core/management/init.py", line 401, in execute_from_command_line utility.execute() File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/core/management/init.py", line 345, in execute settings.INSTALLED_APPS File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/conf/init.py", line 83, in getattr self._setup(name) File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/conf/init File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/conf/__init .py", line 70, in _setup self._wrapped = Settings(settings_module) File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/site-packages/django/conf/init .py", line 177, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/lib/python3.6/importlib/init.py", line 126 , in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/avraam57/avraam57.pythonanywhere.com/djangogirls/settings.py", line 125, in <module> STATIC_ROOT = os.path.join(BASE_DIR, 'static') NameError: name 'os' is not defined Traceback (most recent call last): File "/home/avraam57/.local/bin/pa_autoconfigure_django.py", line 47, in <module> main(arguments['<git-repo-url>'], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke ')) File "/home/avraam57/.local/bin/pa_autoconfigure_django.py", line 37, in main project.run_collectstatic() File "/home/avraam57/.local/lib/python3.6/site-packages/pythonanywhere/django_project.py", line 87, in run_c ollectstatic '--noinput', File "/usr/lib/python3.6/subprocess.py", line 311, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/home/avraam57/.virtualenvs/avraam57.pythonanywhere.com/bin/python', '/home/avraam57/avraam57.pythonanywhere.com/manage.py', 'collectstatic', '--noinput']' returned non-zero exit status 1.

Any help will be apreciated

Your code has a bug in it:

"/home/avraam57/avraam57.pythonanywhere.com/djangogirls/settings.py", line 125, in <module> STATIC_ROOT = os.path.join(BASE_DIR, 'static') 
NameError: name 'os' is not defined

if you wan to use the os module in your settings, you need to import it.

Where you see this line in the settings.py file:

from pathlib import Path

Just add the following line after:

import os

This resolved the bug for me.

Yes, exactly :-)

thank you so much

thank you. by the way I have another problem I will be gratefull if you could help me:

In the template file: blog/templates/blog/post_list.html, following the instructions of the djangogirls tuttorial I write:

<!DOCTYPE html>

<html lang="en">

<head>
    <title>Django Girls blog</title>
</head>
<body>
    <div>
        <h1><a href="/">Django Girls Blog</a></h1>
    </div>

    {% for post in posts %}
<div>
    <p>published: {{ post.published_date }}</p>
    <h2><a href="">{{ post.title }}</a></h2>
    <p>{{ post.text|linebreaksbr }}</p>
</div>
    {% endfor %}

</body>
</html>

but when I run the html file it gives me something that is not correct what I am doing wrong ? please help.

Could you provide more details on what's going wrong? And what do you mean by "running the html file"?

thank you for your willingness to help me. In www.avraam57.pythonanywhere.com it shows the date and time above the title of the post and below it shows the comment of the post. normaly the date and time must be shown under the comment. thanks again

you need to move <p>published: {{ post.published_date }}</p> below <p>{{ post.text|linebreaksbr }}</p>

thanks a lot