dylanleigh / PriceAndNutritionTrackingSystem

PANTS is a self-hosted, open-source nutrition tracker and tool for nutritional data analysis of ingredients and recipes.
Apache License 2.0
116 stars 26 forks source link

KeyError: 'PANTS_DJANGO_SECRET_KEY' with new install #1

Closed JeffCdev closed 4 years ago

JeffCdev commented 5 years ago

Hi Dylan, really want to try your app out, but having an issue. I've tried several time to install on my Rpi3, but I keep getting this error when I run ./manage.py createsuperuser. I've also tried a couple of other ways of installing besides your instructions with the same result. Any hints/suggestions??

Traceback (most recent call last): File "./manage.py", line 22, in execute_from_command_line(sys.argv) File "/home/pi/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 364, in execute_from_command_line utility.execute() File "/home/pi/env/local/lib/python2.7/site-packages/django/core/management/init.py", line 308, in execute settings.INSTALLED_APPS File "/home/pi/env/local/lib/python2.7/site-packages/django/conf/init.py", line 56, in getattr self._setup(name) File "/home/pi/env/local/lib/python2.7/site-packages/django/conf/init.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/home/pi/env/local/lib/python2.7/site-packages/django/conf/init.py", line 110, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/pi/PriceAndNutritionTrackingSystem/pants/pants/settings.py", line 24, in SECRET_KEY = os.environ["PANTS_DJANGO_SECRET_KEY"] File "/home/pi/env/lib/python2.7/UserDict.py", line 40, in getitem raise KeyError(key) KeyError: 'PANTS_DJANGO_SECRET_KEY'

dylanleigh commented 5 years ago

Sorry, there's a missing step in the install instructions - you need to set up an environment variable containing the Django Secret Key. I'll update the documentation ASAP

dylanleigh commented 5 years ago

Updated in e396f372b659281326558d7ea7d25eded4dbcab7

JeffCdev commented 5 years ago

Hi Dylan, Thanks for getting back to me!! (btw, love the committment to writing clear instructions) Getting a lot closer, but still no joy. Since you're obviously serious about getting the docs right, here's my feedback, First, I think you should add this line:

git clone https://github.com/dylanleigh/PriceAndNutritionTrackingSystem.git cd PriceAndNutritionTrackingSystem # add this line pip install -r requirements.txt

Now on to where I'm at. :)

After setting the secret key, I got this error: File "/home/pi/pants/local/lib/python2.7/site-packages/django_filters/filterset.py", line 184 def init(self, data=None, queryset=None, *, request=None, prefix=None): ^ SyntaxError: invalid syntax

After doing some research, I found this:

https://stackoverflow.com/questions/53482772/getting-started-with-django-rest-framework-syntaxerror-invalid-syntax

"My two cents: As @9769953 and @Livonia said the version of django-filter you are using uses in https://github.com/carltongibson/django-filter/blob/master/django_filters/filterset.py#L184 a Python 3.x syntax not compatible with Python 2.7 so this version. The new syntax is specified on https://www.python.org/dev/peps/pep-3102/.

The error that your are getting is on line 184:

File "/Library/Python/2.7/site-packages/django_filters/filterset.py", line 184 def init(self, data=None, queryset=None, *, request=None, prefix=None): ^

SyntaxError: invalid syntax

So:

pip install "django-filter<2.0 "

So I used the pip command, and now I'm getting this error:

File "/home/pi/pants/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 899, in execute_sql raise original_exception django.db.utils.OperationalError: no such table: auth_user

To make sure that I'm not making a newbie error (just starting out with python), here's how I'm creating the virtual environment:

virtualenv -p /usr/bin/python2.7 pants

Thanks again for all your hard work!!!

JeffCdev commented 5 years ago

an addendum (just noticed the copy/paste didn't work quite right). the caret is pointing to the comma after the asterisk: File "/home/pi/pants/local/lib/python2.7/site-packages/django_filters/filterset.py", line 184 def init(self, data=None, queryset=None, *, request=None, prefix=None): ^

JeffCdev commented 5 years ago

darn, still didn't work right, second attempt: an addendum (just noticed the copy/paste didn't work quite right). the caret is pointing to the comma after the asterisk: File "/home/pi/pants/local/lib/python2.7/site-packages/django_filters/filterset.py", line 184 def init(self, data=None, queryset=None, *, request=None, prefix=None): -------------------------------------------^ ignore the dashes

dylanleigh commented 5 years ago

Thanks @JeffCdev - I'm still updating the Installation docs. I'm going to include Python 3+ in requirements from now on as many libraries are deprecating Python 2, that should also resolve the syntax issues.

JeffCdev commented 5 years ago

Thanks Dylan! Just FYI, I have tried the install under python 3.7, also with no joy. I am really looking forward to trying out your work. (so much so that I tried to hack my way through to remove the need to login just to see how things would work, without very much luck :) )

JeffCdev commented 5 years ago

Hi Dylan, Woo Hoo, up and running. A few notes/comments. After the initial install, and reaching this point in the instructions: ./manage.py createsuperuser The process will throw a warning about unapplied migrations, and fail with the error: no such table: auth_user After running python manage.py migrate, I was able to run ./manage.py createsuperuser successfully. However, I ran into issues with the initial error error being ObjectDoesNotExist is not defined. I went ahead and created a second user, and logged in via the admin interface, and then tried the website. I then saw errors: Target Matching Query Does Not Exist with daily_Target = True showing up earlier in the log. Thinking it might be related to the user, I went ahead and filled in a daily target info for the new user. I then ran into KeyErrors: protein_per_j. I then set up the user completely (all targets) leaving no fields blank. At this point, I was able to access the website. So, I think you might want to either add a "sample user" to populate the database to prevent this issue, and/or modify the code. Thank you so very, very much for this project! Now that I'm able to run it, I am looking forward to exploring its functionality.

dylanleigh commented 5 years ago

Thanks @JeffCdev for all the reports - I haven't had time to look at it this week but as soon as I can I will fix the code so these missing object issues won't occur on a fresh install.

dylanleigh commented 5 years ago

These haven't been tested on a fresh install yet, but don't break an existing install or unit tests:

Initial migration added to docs in 82cbdfbc9ffcc424d94676a1e54ff5abe43dcb25 Fixed Target;s Exceptions called incorrectly in a4b934bd0b4268f5a058ffaac3d8cab19fc907f9 Fixed home page missing defaults if protein_per_j and fibre_per_j can't be derived from the daily target in 4a8bba7a2fa027c6f90f414bd44188cb08aabcb6

JeffCdev commented 5 years ago

Thanks Dylan! I have to tell you, now that I've had a chance to work with your app, you've done spectacular work. The thought that you've put into the app shows you really understand what people will want to track, and I very much look forward to your future work. I do have a couple of suggestions. First, the addition of ingredients. I'm from the states, so we're still kcal rather than kj, but I've been using an Aussie website to get data. However, even with that site, kj per kilogram is a bit like furloughs per fortnight. :) Having functionality that would allow a user to enter kj (or kcal) and other nutritional info by the suggested serving in grams (like what is listed on the nutritional data section of a package) and then converting it to kilograms would really enhance the user experience. Second, I'm assuming based on the personal info that you've shared that the reason you're putting so much time and effort into the project is that you are concerned about your health. So, my second suggestion would be to add some type of bio-metric info that could be track along with nutrition so that a person could see the results. Just adding body weight at a date would be great, but other info (bmi, blood pressure, etc.) would be useful. I'm going to hold off on redoing an install at this point, since I'm concerned about losing all of the ingredient info I've entered so far, but when I have some time, I'll set up another virtual environment and do a second install and let you know how it goes. Again, thank you very much!

dylanleigh commented 4 years ago

Sorry I missed your comment @JeffCdev , for some reason I didn't get a notification. Glad you're finding the app useful, and thanks for all your feedback.

Regarding data entry: I've added some new TODOs to the roadmap to make data entry easier (including allowing per-something other than kg entry). Also there is now a fixture with some sample ingredient data including basics like eggs, flour, oats etc.

Biometrics: This has been planned for a while, there is a section in the roadmap for adding diary entries for exercise sessions and recording metrics (blood pressure, pulse etc). The diary code is already set up to be compatible non-food entries although none have been implemented yet.