I am trying to deploy a Django application using the default SQLite database to Elastic Beanstalk. The application works fine locally, however, on server, I get the error as :
Any idea what's wrong? Can we not deploy SQLite app on AWS EBS?
Here is my project structure that is getting deployed
├── .ebextensions
│ ├── django.config
├── app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ ├── models.py
│ ├── static
│ │ └── app
│ │ ├── app.js
│ │ ├── logo.svg
│ │ └── style.css
│ ├── templates
│ │ └── app
│ │ ├── hello.html
│ │ ├── index.html
│ │ └── job_detail.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db.sqlite3
├── env
│ ├── All Virtual env related files
├── images
│ ├── Photo_on_5-9-14_at_2.31_PM.jpg
│ ├── Photo_on_5-9-14_at_2.32_PM.jpg
│ └── Photo_on_5-9-14_at_2.32_PM_v4McLzE.jpg
├── myproject-test
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── requirements.txt
├── staticfiles
│ |-- All static files collected using collectstatic
│ ├── app
│ │ ├── app.js
│ │ ├── logo.svg
│ │ └── style.css
│ └── subscribe
│ ├── email-icon.png
│ ├── main.css
│ └── main.js
├── subscribe
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── form.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_subscribe_option_alter_subscribe_email_and_more.py
│ │ ├── 0003_alter_subscribe_option.py
│ ├── models.py
│ ├── static
│ │ └── subscribe
│ │ ├── email-icon.png
│ │ ├── main.css
│ │ └── main.js
│ ├── templates
│ │ └── subscribe
│ │ ├── subscribe.html
│ │ └── thank_you.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── templates
│ └── base.html
├── upload
│ └── images
│ ├── Photo_on_5-9-14_at_2.31_PM.jpg
│ └── Photo_on_5-9-14_at_2.31_PM_3.jpg
└── uploads
├── __init__.py
├── admin.py
├── apps.py
├── forms.py
├── images
│ └── Photo_on_5-9-14_at_2.31_PM_3.jpg
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_uploadfile.py
│ ├── 0003_alter_uploadfile_file.py
│ ├── __init__.py
├── models.py
├── templates
│ └── uploads
│ ├── add_file.html
│ └── add_image.html
├── tests.py
├── urls.py
└── views.py
Deployment process:
Zip all the necessary files
Create AWS EBS application with Python
Add environment variables
Create app and access URL
Please help.
I'm trying to use Black to format my Django code. It works fine in most directories. However, I get the Unicode decode error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte on the .py files in one directory in particular. The files are in UTF-8, but I have tried multiple different other encodings and have tried deleting and recreating files which hasn't resolved the issue. I'm working in an Anaconda environment, but deactivating that doesn't make any difference. I've also disabled most of my VS Code extensions.
I have looked at many SO postings on this, but none of the suggestions thus far have helped. I'm using VS Code on a Mac and have a feeling it is something to do with the fact that in the past I have edited the same code on a Windows machine using VS Code with WSL (code synced with a GitHub repo), but can't figure out how to address it. I've put a sample Traceback call below. Any help would be much appreciated!
Edit: If I cut and paste any of the files into another directory, then Black works fine and I don't get any encoding error messages. Which suggests there may be a directory-level issue at play?
(base) ➜ healthtic git:(master) ✗ black pages/views.py
Traceback (most recent call last):
File "/Users/jh/opt/anaconda3/bin/black", line 8, in <module>
sys.exit(patched_main())
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/black/__init__.py", line 1130, in patched_main
main()
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/black/__init__.py", line 411, in main
sources = get_sources(
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/black/__init__.py", line 477, in get_sources
gitignore = get_gitignore(root)
File "/Users/jh/opt/anaconda3/lib/python3.8/site-packages/black/files.py", line 123, in get_gitignore
lines = gf.readlines()
File "/Users/jh/opt/anaconda3/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Further edit: As mentioned above if I move files out of this directory, Black works fine, if I move them back (without any changes), the 0xFF unicode error recurs. I have attached my directory structure below, as it may be relevant that I have webpack and node modules in there for some of the frontend. My impression is that maybe a BOM may be being added somehow in the directory?
├── Dockerfile
├── accounts
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── appointments
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── cloud_sql_proxy
├── cloudmigrate.yaml
├── config
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── basesettings.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── docker-compose.yaml
├── front-end
│ ├── App\ copy.js
│ ├── App.js
│ ├── index\ copy.js
│ └── index.js
├── logfile
├── manage.py
├── node_modules
│ ├── #babel
│ ├── #discoveryjs
│ ├── #types
│ ├── #webassemblyjs
│ ├── #webpack-cli
│ ├── #xtuc
│ ├── acorn
│ ├── ajv
│ ├── ajv-keywords
│ ├── ansi-styles
│ ├── babel-loader
│ ├── babel-plugin-dynamic-import-node
│ ├── babel-plugin-polyfill-corejs2
│ ├── babel-plugin-polyfill-corejs3
│ ├── babel-plugin-polyfill-regenerator
│ ├── big.js
│ ├── browserslist
│ ├── buffer-from
│ ├── call-bind
│ ├── caniuse-lite
│ ├── chalk
│ ├── chrome-trace-event
│ ├── clone-deep
│ ├── color-convert
│ ├── color-name
│ ├── colorette
│ ├── commander
│ ├── commondir
│ ├── convert-source-map
│ ├── core-js-compat
│ ├── cross-spawn
│ ├── debug
│ ├── define-properties
│ ├── electron-to-chromium
│ ├── emojis-list
│ ├── enhanced-resolve
│ ├── envinfo
│ ├── es-module-lexer
│ ├── escalade
│ ├── escape-string-regexp
│ ├── eslint-scope
│ ├── esrecurse
│ ├── estraverse
│ ├── esutils
│ ├── events
│ ├── execa
│ ├── fast-deep-equal
│ ├── fast-json-stable-stringify
│ ├── fastest-levenshtein
│ ├── find-cache-dir
│ ├── find-up
│ ├── function-bind
│ ├── gensync
│ ├── get-intrinsic
│ ├── get-stream
│ ├── glob-to-regexp
│ ├── globals
│ ├── graceful-fs
│ ├── has
│ ├── has-flag
│ ├── has-symbols
│ ├── human-signals
│ ├── import-local
│ ├── interpret
│ ├── is-core-module
│ ├── is-plain-object
│ ├── is-stream
│ ├── isexe
│ ├── isobject
│ ├── jest-worker
│ ├── js-tokens
│ ├── jsesc
│ ├── json-parse-better-errors
│ ├── json-schema-traverse
│ ├── json5
│ ├── kind-of
│ ├── loader-runner
│ ├── loader-utils
│ ├── locate-path
│ ├── lodash
│ ├── lodash.debounce
│ ├── loose-envify
│ ├── make-dir
│ ├── merge-stream
│ ├── mime-db
│ ├── mime-types
│ ├── mimic-fn
│ ├── minimist
│ ├── ms
│ ├── neo-async
│ ├── node-releases
│ ├── npm-run-path
│ ├── object-assign
│ ├── object-keys
│ ├── object.assign
│ ├── onetime
│ ├── p-limit
│ ├── p-locate
│ ├── p-try
│ ├── path-exists
│ ├── path-key
│ ├── path-parse
│ ├── pkg-dir
│ ├── punycode
│ ├── randombytes
│ ├── react
│ ├── react-dom
│ ├── rechoir
│ ├── regenerate
│ ├── regenerate-unicode-properties
│ ├── regenerator-runtime
│ ├── regenerator-transform
│ ├── regexpu-core
│ ├── regjsgen
│ ├── regjsparser
│ ├── resolve
│ ├── resolve-cwd
│ ├── resolve-from
│ ├── safe-buffer
│ ├── scheduler
│ ├── schema-utils
│ ├── semver
│ ├── serialize-javascript
│ ├── shallow-clone
│ ├── shebang-command
│ ├── shebang-regex
│ ├── signal-exit
│ ├── source-list-map
│ ├── source-map
│ ├── source-map-support
│ ├── strip-final-newline
│ ├── supports-color
│ ├── tapable
│ ├── terser
│ ├── terser-webpack-plugin
│ ├── to-fast-properties
│ ├── unicode-canonical-property-names-ecmascript
│ ├── unicode-match-property-ecmascript
│ ├── unicode-match-property-value-ecmascript
│ ├── unicode-property-aliases-ecmascript
│ ├── uri-js
│ ├── v8-compile-cache
│ ├── watchpack
│ ├── webpack
│ ├── webpack-cli
│ ├── webpack-merge
│ ├── webpack-sources
│ ├── which
│ ├── wildcard
│ └── yocto-queue
├── notes.md
├── package-lock.json
├── package.json
├── pages
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── patient
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── patientinfo
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── readme.md
├── requirements.txt
├── static
│ ├── css
│ ├── images
│ ├── index-bundle.js
│ ├── index-bundle.js.LICENSE.txt
│ └── js-bundle.js
├── staticfiles
│ ├── admin
│ ├── css
│ └── images
├── templates
│ ├── _base.html
│ ├── account
│ ├── appointments
│ ├── frontend.html
│ ├── hello_webpack.html
│ ├── home.html
│ ├── patient
│ └── patientinfo
├── todos.md
└── webpack.config.js
Turns out it was my .gitignore file that was encoded in UTF-16 that was the problem. This seemed to stop Black from working in the whole directory. When I moved all of my files to another directory, I only moved the visible files (so not .gitignore), hence the unusual behaviour. Changing the .gitignore to UTF-8 solved the problem.
I don't even know what django is, but I had the same problem in a non-django program.
In that code fragment was the problem that now is fixed:
open(document.txt, mode= "r", encoding="utf8")
As you can see, the encoding it's utf8, without the "-". I used that code to open documents and read it. I hope it'll be useful!
When i run python manage.py tests i get an error saying that some test module is not found.
I am using PyCharm, Django 2.1.4 and W10 on Ubuntu.
The error:
======================================================================
ERROR: projectname.projectname (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: projectname.projectname
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "/usr/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
ModuleNotFoundError: No module named 'projectname.projectname'
What I've tried
python manage.py runserver and it runs just fine.
Add projectname to INSTALLED_APPS
Create and app called tests
My project structure
Django
│ ├── requirements.txt
│ └── projectname
│ ├── __init__.py
│ ├── manage.py
│ └── projectname
│ ├── apps
│ │ ├── accounts
│ │ │ ├── admin.py
│ │ │ ├── apps.py
│ │ │ ├── __init__.py
│ │ │ ├── migrations
│ │ │ │ ├── __init__.py
│ │ │ ├── models
│ │ │ │ ├── __init__.py
│ │ │ │ ├── profiles.py
│ │ │ │ └── users.py
│ │ │ ├── serializers
│ │ │ │ └── __init__.py
│ │ │ ├── tests.py
│ │ │ ├── urls.py
│ │ │ └── views
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ ├── db.sqlite3
│ ├── __init__.py
│ ├── settings
│ │ ├── base.py
│ │ ├── development.py
│ │ ├── production.py
│ ├── static
│ ├── templates
│ ├── urls.py
│ └── wsgi.py
I just want to run my tests like in any other django project...
I have never encountered this problem before so any help is appreciated! :)
Well, well...it turns out that changing the folder was the solutio, though i have projects working that share the same folder name so i don't really know what happend with this one.
Before:
Django
│ └── projectname
│ └── projectname
After:
Django
│ └── othername
│ └── projectname
I have been working on the issue of duplicate labels in Django and from this answer I have added the following files to my "jobs" project folder:
jobs/apps.py
# jobs/apps.py
from django.apps import AppConfig
class JobsConfig(AppConfig):
name = 'jobs'
verbose_name = "jobs2"
jobs/init.py
# jobs/__init__.py
default_app_config = 'jobs.apps.JobsConfig'
This hasn't really helped much and I still get the error when trying syncdb:
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: jobs
Also, changing from "name = 'jobs'" to "name = 'jobs2'" just gives me the error:
ImportError: No module named jobs2
File Structure
/opt/Webapp
├── userfiles
├── templates
│ └── admin
│ └── base.html
├── static
│ ├── admin_tools
│ │ ├── images
│ │ │ └── apto.gif
│ │ └── css
│ │ └── theming.css
│ └── admin
│ └── css
│ └── base.css
├── smartrecruitment
│ ├── wsgi.py
│ ├── urls.py
│ ├── settings.pyc
│ ├── settings.py
│ ├── __init__.pyc
│ └── __init__.py
├── requirements.txt
├── manage.py
├── jobs
│ ├── views.py
│ ├── urls.py
│ ├── tests.py
│ ├── testhelpers.py
│ ├── templates
│ │ └── jobs
│ │ ├── test.html
│ │ ├── success.html
│ │ ├── registration.html
│ │ ├── registrationcomplete.html
│ │ └── application.html
│ ├── tables.py
│ ├── static
│ │ └── jobs
│ │ ├── styles
│ │ │ ├── index.css
│ │ │ ├── hide_admin_original.css
│ │ │ └── application.css
│ │ ├── style.css
│ │ └── images
│ │ └── apto.gif
│ ├── models.py
│ ├── migrations
│ │ ├── __init__.py
│ │ ├── 0002_auto__del_field_registrant_name__add_field_registrant_first_name__add_.py
│ │ └── 0001_initial.py
│ ├── lists.py
│ ├── __init__.pyc
│ ├── __init__.py
│ ├── forms.py
│ ├── apps.pyc
│ ├── apps.py
│ └── admin.py
├── fileuploads
│ ├── tests.py
│ ├── templates
│ │ └── fileuploads
│ │ ├── index.html
│ │ ├── details.html
│ │ ├── base.html
│ │ └── add.html
│ ├── models.pyc
│ ├── models.py
│ ├── __init__.pyc
│ ├── __init__.py
│ ├── forms.pyc
│ ├── forms.py
│ ├── context_processors.py
│ └── admin.pyc
├── dashboard.pyc
└── dashboard.py
You have a mix of old-style (south: 0002_auto_del...) and new-style (django: 0001_initial) migrations in your jobs app. Easiest fix would be to delete all numbered migrations rm jobs/migrations/0???_*.py* and recreate migrations by running manage.py makemigrations
How do import my class from a specific directory (in my case root directory i want to keep it).
So, i have following directory map, now i need to load the class parsePresets from myglobal.py file, which is located in root directory: /var/tmp/mypython directory.
but, i want to import that from class/methods from my new module: /var/tmp/mypython/media/test.py with:
from myglobal import parsePresets
but i am getting:
from myglobal import parsePresets
ImportError: No module named myglobal
i also have init.py in root directory and in the media directory.
$ cd /var/tmp/mypython; tree
.
├── arduino
│ ├── arduino.diest.c
│ ├── arduino.gent.c
│ ├── arduino.lalouvier.c
│ ├── arduino.makenoise.c
│ ├── arduino.servo.c
│ ├── arduino.string.c
│ ├── arduino.tcpserver.c
│ ├── arduino.tcpserver.c~
│ ├── arduino.test.sh
├── bash
│ ├── all.sh
│ ├── alsa-info.sh
│ ├── asound.conf
│ ├── autoreboot.sh
│ ├── diskfix.sh
│ ├── kernelfix.sh
│ ├── update.sh
│ └── usbformat.sh
├── chrome.py
├── download.py
├── download.sh
├── gui.py
├── image
│ ├── a.png
│ ├── b.gif
│ ├── cross_new.png
│ ├── e150
│ │ ├── 1.png
│ │ ├── de.png
│ │ ├── en.png
│ │ ├── __init__.py
│ │ └── nl.png
│ ├── __init__.py
│ ├── logo.png
│ ├── menu.jpg
│ └── slider_btn.png
├── __init__.py
├── INSTALL
├── ip.py
├── loading.py
├── logout.py
├── media
│ ├── __init__.py
│ ├── test.py
├── menu.py
├── myglass.py
├── myglass.pyc
├── myglobal.py
├── myglobal.pyc
├── rightclick.py
├── runme.sh
├── server.py
├── server.pyc
├── src.nja
├── test
│ ├── Button.py
│ ├── json.py
│ ├── json.pyc
│ ├── keyboard.py
│ ├── loop.sh
│ ├── mytimer.py
│ ├── qtclick.py
│ ├── qtmouse.py
│ ├── qt.py
│ ├── qtwindows7.py
│ ├── shape.py
│ ├── skeleton.py
│ ├── slider.py
│ ├── testpreview.py
│ ├── test.py
│ ├── Text.py
│ ├── transparent.py
│ ├── transparentwindow.py
│ └── Vscale.py
├── test.py
├── unavailable.py
├── upload.sh
└── internet
├── backup
├── protocol.txt
└── server.py
You can add sys.path.append(/var/tmp/mypython/media/) to your script.
EDIT:
$ cat >> /var/tmp/mypython/stackoverflow.py <<\EOF
import sys
sys.path.append("/var/tmp/mypython/")
from myglobal import parsePresets
EOF
$ python /var/tmp/mypython/stackoverflow.py
or with NINJA-IDE
Running: /var/tmp/mypython/media/stackoverflow.py (Wed Dec 11 13:37:25 2013)
Execution Successful!
Use relative imports
from ..myglobal import parsePresets
The extra periods . take you "out" a level in your hierarchy.