Error in deploy with NameError: name 'static' is not defined

1

When uploading files to the server in pythonanywere I get the following error line. Any ideas on how to solve it?

 File "/home/factura/wp/wp/wp/urls.py", line 36, in <module>
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
NameError: name 'static' is not defined

urls.py

    from django.contrib import admin
    from django.urls import path
    from django.conf import settings

    urlpatterns = [

        path('admin/', admin.site.urls)...
    ]

   if settings.DEBUG:
    from django.conf.urls.static import static
**urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)**

Directory structure

├── Projecto
│   ├── migrations
│   │   └── __pycache__
│   ├── __pycache__
│   ├── static
│   │   └── projecto
│   │       ├── css
│   │       ├── img
│   │       ├── js
│   │       └── vendor
│   │           ├── bootstrap
│   │           │   ├── css
│   │           │   └── js
│   │           ├── font-awesome
│   │           │   ├── css
│   │           │   ├── fonts
│   │           │   ├── less
│   │           │   └── scss
│   │           └── jquery
│   └── templates
│       └── root
├── media
│   └── projects
├── facturacion
│   ├── migrations
│   │   └── __pycache__
│   ├── __pycache__
│   └── templates
│       └── factura
└── wp
    └── __pycache__

settings.py

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
    
asked by Developer 07.12.2018 в 23:32
source

1 answer

1

Inside the settings.py of the app you must put the code at the end of the whole

STATIC_ROOT = '/home/nombreUser/nombreProyecto/static'

to refer to your static files, in addition to the configuration offered by PythonAnyWhere you will have to configure the static files section as shown below:

I recommend checking the path of your static folder, and verify that the written well Greetings!

    
answered by 09.12.2018 / 15:53
source