orionblastar / K666

K666 is forum discussion software, this is an attempt to write the Free version FreeK666 without violating copyright
http://k666.kr5ddit.com
MIT License
5 stars 0 forks source link

Do the django tutorial! #25

Open procrasti opened 8 years ago

procrasti commented 8 years ago

You might want to run through the django tutorial so you have a better idea what you are doing. I'll put the tutorial pages up here, and you can check them off, so I know roughly what you know and make things a bit easier for us... Tackle about 1 a day or something at the start of your coding sessions?

Advanced topics:

orionblastar commented 8 years ago

Yikes that is a lot to go through. Hope I can remember it all. I'm doing the first tutorial and it seems it is for Python 3.4 and above. Might take me a long time to complete.

orionblastar commented 8 years ago

Well I got to the first one, and looks like it doesn't know what include means in the urls.py in mysite. I think I might have an older version of Django installed or something. I reached a stopping point until I figure out a way around the error in the tutorial.

orionblastar commented 8 years ago

urls.py:

from django.conf.urls import include, url from django.contrib import admin

urlpatterns = [ url(r'^polls/', include('polls.urls')), url(r'^admin/', admin.site.urls), ]

File "/home/norman/tutorial/mysite/polls/urls.py", line 7, in url(r'^polls/', include('polls.urls')), NameError: name 'include' is not defined

procrasti commented 8 years ago

$ python -c "import django; print(django.get_version())"

https://docs.djangoproject.com/en/1.9/topics/install/#installing-an-official-release-with-pip

Let's set your environment up first.

# Create a working directory
$ mkdir -p ~/src/djangotutorial
$ cd ~/src/djangotutorial

# Initialise a git repository right here
$ git init .

# Create a python virtual environment
$ virtualenv -p python3 env

# Maybe you want to ignore env files in your .gitignore?

# Use the virtual environment instead of the system environment
$ . ./env/bin/activate.sh

# You know you are in a virtual environment because the prompt changes

# Install django with pip
(env) $ pip install Django

# Maybe you want 1.9 exactly (it won't matter that much probably) (haven't tested this)
(env) $ pip install Django==1.9

# Check you've got the right versions
(env) $ python --version
(env) $ python -c "import django; print(django.get_version())"

Then you should be good to go on the tutorial.

You could skip all that and just

$ sudo apt-get install python3
$ sudo pip install Django==1.9

But who likes to mess with root, and what effects it will have on other software?

procrasti commented 8 years ago

You shouldn't try to do this all at once...

Maybe try one at the start of every other coding session or whatever.

Q: How do eat an elephant? A: One bite at a time.

orionblastar commented 8 years ago

I got an error in the virtual environment in instaling Django:

norman@Lazarus0 ~/src/djangotutorial $ git init . Initialized empty Git repository in /home/norman/src/djangotutorial/.git/ norman@Lazarus0 ~/src/djangotutorial $ virtualenv -p python3 env Running virtualenv with interpreter /usr/bin/python3 Using base prefix '/usr' New python executable in /home/norman/src/djangotutorial/env/bin/python3 Also creating executable in /home/norman/src/djangotutorial/env/bin/python Installing setuptools, pip, wheel...done. norman@Lazarus0 ~/src/djangotutorial $ pip install Django Requirement already satisfied (use --upgrade to upgrade): Django in /home/norman/tutorial/django norman@Lazarus0 ~/src/djangotutorial $ pip install Django==1.9 Collecting Django==1.9 /usr/local/lib/python2.7/dist-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning /usr/local/lib/python2.7/dist-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading Django-1.9-py2.py3-none-any.whl (6.6MB) 100% |████████████████████████████████| 6.6MB 206kB/s Installing collected packages: Django Found existing installation: Django 1.11.dev20160613154551 Can't uninstall 'Django'. No files were found to uninstall.

Can't roll back Django; was not uninstalled Exception: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run prefix=options.prefix_path, File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 742, in install kwargs File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 831, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1032, in move_wheel_files isolated=self.isolated, File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 346, in move_wheel_files clobber(source, lib_dir, True) File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 317, in clobber ensure_dir(destdir) File "/usr/local/lib/python2.7/dist-packages/pip/utils/init**.py", line 83, in ensure_dir os.makedirs(path) File "/usr/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/Django-1.9.dist-info'

procrasti commented 8 years ago

You installed the virtual environment, but you did not activate it... You are using the global python, pip and django... not the local virtual env ones.

After you run virtualenv, you must SOURCE env/bin/activate

orionblastar commented 8 years ago

norman@Lazarus0 ~/src/djangotutorial $ . ./env/bin/activate.sh bash: ./env/bin/activate.sh: No such file or directory norman@Lazarus0 ~/src/djangotutorial $ I tried it this way:

norman@Lazarus0 ~/src/djangotutorial $ source env/bin/activate source: command not found norman@Lazarus0 ~/src/djangotutorial $ sudo apt-get install source Reading package lists... Done Building dependency tree
Reading state information... Done E: Unable to locate package source norman@Lazarus0 ~/src/djangotutorial $

orionblastar commented 8 years ago

I'm running apt-get commands to remove packages that can't upgrade and remove the old kernel headers to install new ones. I posted more info to Kr5ddit, but it seems to be down now.

I run Linux Mint 17.3 and haven't upgraded to 18 yet.

I'll figure it out somehow, I might have to check the Linux partition for errors using fsck.

This is what I get trying to post to Kr5ddit:

Gateway Timeout

The gateway did not receive a timely response from the upstream server or application.

Apache/2.4.10 (Debian) Server at kr5ddit.com Port 443

orionblastar commented 8 years ago

Ok booted into recovery mode, ran fsck fixed errors, drive was mounted with the wrong time stamp, fixed some sector errors. Ran DPGK to fix broken packages, and a lot of other things. Then rebooted but it locked up in the login screen forcing me to power reset my PC. Something strange is going on.

I might have to reformat my PC sometime soon if I don't figure out what is causing this problem.

It is three years old, and I think there is a heating issue or something, I'll have to check the case and fans for dust and use my Datavax to blow the dust out. If power supply has dust in it and I can't blow it out might need a new power supply which I can't afford yet.

I've spent hours trying to figure out what is going on, and it seems to be a problem I can't seem to fix yet.

I was finally able to make a post on Kr5ddit, after retrying a dozen times or so. Not sure what your ideas are for fixing this problem. I might have to uninstall some third party apps in my Linux MInt if they are causing package problems or something. See if it works then.

orionblastar commented 8 years ago

After removing and reinstalling packages on my Linux Mint system:

It worked! Congratulations on your first Django-powered page.

Of course, you haven't actually done any work yet. Next, start your first app by running python manage.py startapp [app_label].

You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

I think I accidentally put mysite in the src/djangotutorial directory as well, instead of the root of that directory. I've been sick, and also helping my mother who we are told by her doctor that her lungs are in their last stage now. So I haven't been thinking clearly. I also got root and gum problems with my teeth and they hurt and I'm using Sensodyne and will see the dentist in Tuesday to start the cleaning process.

But at least I figured out a way around the problems I was having. I almost reformatted the drive and switch from Mint to Debian or something.

orionblastar commented 8 years ago

Ok I think I might have made progress over part one of the tutorial.

http://127.0.0.1:8000/polls/

Hello, world. You're at the polls index.

But this happens in the root directory:

http://127.0.0.1:8000/

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

^polls/
^admin/

The current URL, , didn't match any of these.

procrasti commented 7 years ago

Cool... actually you made progress... sorry I didn't see this message earlier... You'll have to alert me on kr5ddit I guess.

Are you still at this point, or have you fallen back a little bit? Can you get to this point again? Let me know...

Basically you don't have a the root url ^$ mapped to a view... it's nothing to worry about for now.

orionblastar commented 7 years ago

It has been so long I forgot where I was and which subdirectory I worked on last, etc. I also deleted some old subdirectories because I was running out of hard drive space. The last commit by me here should be the last known working version I worked on. Trying to view issues already resolved is hard for me the way it is designed here.

procrasti commented 7 years ago

When you feel like you've forgotten, just go back either to the beginning, or at least back to a tutorial you feel somewhat comfortable with... The earlier tutorials are more required, and get you the bulk of the way there in many cases... once you're a way in, you'll find the earlier tutorials become ingrained.

A good idea is to start a new module that does something small and can be separated out... and run through the tutorials, but apply to your module, not the tutorial examples.

orionblastar commented 6 years ago

I get this message trying to do the 1.9 tutorial:

This document is for an insecure version of Django that is no longer supported. Please upgrade to a newer release!

I thought for the New Year I should get back and learning Python again, but did you have to switch to a newer version as well?

orionblastar commented 4 years ago

My hard drive crashed in Linux and I lost all the info I was working on, not counting what is in the repository.

I am taking this class: https://www.udemy.com/course/automate/

I am halfway though it. I need to know more Python before I can do the Django tutorial. I spend 15 to 30 minutes a day on learning Python.