Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment: Part one of Django tutorial #3

Open
steven-king opened this issue Jan 29, 2014 · 18 comments
Open

Assignment: Part one of Django tutorial #3

steven-king opened this issue Jan 29, 2014 · 18 comments

Comments

@steven-king
Copy link
Owner

Do Part 1: https://docs.djangoproject.com/en/1.6/intro/tutorial01/

@duanyang
Copy link

So we need to follow the instructions and do sections from "creating project" to "play with API". Is that correct?

@epait
Copy link

epait commented Jan 31, 2014

Yeah - doing everything on that page to create a poll app.

@epait
Copy link

epait commented Jan 31, 2014

So I just did Part 1 of the Tutorial and went to move on to Part 2 (I setup the settings.py file the way we went through in class instead of the defaults that appear), and when I went to log-in to the admin, I got an error saying that I was using the Sites Framework without having a SITE_ID set. I was able to get around that by commenting out django.contrib.sites in the installed apps, but the admin site isn't styled. Is there something else I need to change in the settings.py file to make sure the styling for that is getting called?

Here are screenshots of my settings.py file and what the admin site looks like.
screen shot 2014-01-30 at 9 48 33 pm
screen shot 2014-01-30 at 9 48 43 pm

@epait
Copy link

epait commented Jan 31, 2014

FIX: In settings.py there needs to be a trailing comma after os.path.join(PROJECT_ROOT, 'static_media') in the STATICFILES_DIRS

@shawannewang
Copy link

I followed the class instructions and tried following the link's instructions and ended up having the directories in different places. Can someone help? I'm pretty confused right now...

screenshot from 2014-02-02 00 06 23

screenshot from 2014-02-01 23 27 41

@duanyang
Copy link

duanyang commented Feb 2, 2014

Hi guys:

I am really stuck with the assignment. I look over the part 1 and understand pretty well what is going on. However, it seems that I have trouble implementing the steps on my computer.

I have created a new virtual environment called assignment-env
Then I activate the assignment-env
After that, I run the command pip install Django==1.6. (The tutorial is for 1.6)
Next, I set up a project called mysite just as the part 1 instruction states
Then, I try to run the command python manage.py syncdb.

However, I can't get this command to work. I refer back to the class slides for help and didn't see I did anything wrong. I also tried to install different version of Django and it still doesn't work.

Can anyone help me. I am running Ubuntu.

@steven-king
Copy link
Owner Author

@duanyang Your file structure should look like this.
screen shot 2014-02-02 at 7 44 51 pm

Yu can move them using the OS or you can and should do it by using the mv [what] [to]

@steven-king
Copy link
Owner Author

@epait Thanks for helping and sharing!

@caseymm
Copy link

caseymm commented Feb 3, 2014

@duanyang Make sure that you're in the mysite directory (while in your venv before trying to run the syncdb command.

(mysite-env)$ cd mysite
(mysite-env) mysite $ python manage.py syncdb

@caseymm
Copy link

caseymm commented Feb 3, 2014

@shawannewang Make sure that you're in the right directory when you're running commands.

$ cd DJANGO_PROJECTS
DJANGO_PROJECTS $ virtualenv mysite-env
DJANGO_PROJECTS $ . mysite-env/bin/activate
(mysite-env) DJANGO_PROJECTS $ pip install django
(mysite-env) DJANGO_PROJECTS $ django-admin.py startproject mysite
(mysite-env) DJANGO_PROJECTS $ cd mysite
(mysite-env) mysite $ …

###Make sure you’re in the mysite directory (top level) before running startapp or syncdb
Also, sometimes in Ubuntu you'll instead run:

(mysite-env) DJANGO_PROJECTS $ django-admin startproject mysite
#no .py on django-admin

@shawannewang
Copy link

@caseymm Thanks! It worked up until I tried django-admin startproject mysite. I tried it with and without .py but it keeps saying 'command not found' or this shows up:

'did you mean: Command 'django-admin' from package 'python-django' (main)'

@caseymm
Copy link

caseymm commented Feb 3, 2014

@shawannewang Try this:

sudo ln -s /usr/lib/python2.7/dist-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py

http://wecanrify.wordpress.com/2012/07/05/installing-the-django-framework-on-ubuntu-12-04-3/

@shawannewang
Copy link

@caseymm

It ran (I entered the code and then my password when prompted, so it should've worked), but when I tried django-admin again it still gave me command not found. I tried googling solutions, but most of them seemed to give similar answers which don't work either. Not sure what is up with that...thank you for the help, though! I appreciate it a lot.

Edit: Oh! I figured out why now. I tried django-admin.py --help and it worked totally fine afterwards. hm...

@steven-king
Copy link
Owner Author

thanks @caseymm

@duanyang
Copy link

duanyang commented Feb 6, 2014

Hi guys:

For part 2 of tutorial, I update admin.py with following codes:

from django.contrib import admin
from polls.models import Poll

class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
('Date information', {'fields': ['pub_date']}),
]

admin.site.register(Poll, PollAdmin)

However, when I refresh my webpage, I didn't get the same result as the tutorial states.

The screenshot below shows what I get. Somehow, the phrase "Date information" doesn't show up as it suppose to. Does anyone get similar problem?

screenshot from 2014-02-06 11 04 48

@steven-king
Copy link
Owner Author

The code you provided is displaying properly. I am not sure where you are in the tutorial but if you are trying to do this: https://docs.djangoproject.com/en/dev/_images/admin07.png
Then then you should be viewing a different page. Look at the bread crumbs. pools->question.
Let me know if I am misunderstanding or let me see better where you are in the tutorial.

@duanyang
Copy link

Hi guys:

I am currently doing the section "Use generic views: Less code is better" on https://docs.djangoproject.com/en/1.6/intro/tutorial04/

I follow the instruction and make necessary change.

However, I get the following message when I try to run the poll (127.0.0.1:800/polls/1)

screenshot from 2014-02-09 20 49 18

Does anyone know what is going on?

@epait
Copy link

epait commented Feb 10, 2014

It would be a lot easier to help if you also posted your code, but since the error is saying DetailView must be called with a pk or slug, it looks like you might have skipped over changing 'poll_id' to 'pk' in your urls.py file for DetailView and ResultsView since "The DetailView generic view expects the primary key value captured from the URL to be called "pk", so we’ve changed poll_id to pk for the generic views.".
screen shot 2014-02-09 at 9 31 18 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants