I have been going through the tutorial, adapting it to my project as
necessary, and have a couple questions.
1. This must be glaringly obvious, but how do I use django to load my
homepage (index.html in the public_html root)? I understand about
views and url matching, but there is no views.py in the main directory
and I am not sure if I am supposed to create one or not. In other
words, how does django know where to find the page to load when a
visitor simply goes to mysite.com, instead of
mysite.com/something_to_match?
2. The project I am working on has a few tables: media, articles, and
authors. An article can have one author and one or more rows in the
media table associated with it. I currently have an app called
"tables", in which I plan to define the three tables in models.py (I
am only working with authors as a test). All my views, urls, and so
forth will be inside this tables app. Is this generally recommended,
or should I have an app for each table? The tutorial has two tables
defined, but the urls are all /polls/[something], whereas my urls
might be /authors/, /author/[id], /article/[id], and so on (not
sharing /[app_name]/... like the tutorial does). I hope that made
sense!
--
Have a great day,
Alex (msg sent from GMail website)
meh...@gmail.com; http://www.facebook.com/mehgcap
Hello all,
I was on this list a few months ago, but was unable to get a
django-friendly web host. I am now helping with a site on Bluehost,
which does support django, and I am hoping to be given permission by
the guy in charge to use django instead of php for our project.I have been going through the tutorial, adapting it to my project as
necessary, and have a couple questions.1. This must be glaringly obvious, but how do I use django to load my
homepage (index.html in the public_html root)? I understand about
views and url matching, but there is no views.py in the main directory
and I am not sure if I am supposed to create one or not. In other
words, how does django know where to find the page to load when a
visitor simply goes to mysite.com, instead of
mysite.com/something_to_match?
2. The project I am working on has a few tables: media, articles, and
authors. An article can have one author and one or more rows in the
media table associated with it. I currently have an app called
"tables", in which I plan to define the three tables in models.py (I
am only working with authors as a test). All my views, urls, and so
forth will be inside this tables app. Is this generally recommended,
or should I have an app for each table? The tutorial has two tables
defined, but the urls are all /polls/[something], whereas my urls
might be /authors/, /author/[id], /article/[id], and so on (not
sharing /[app_name]/... like the tutorial does). I hope that made
sense!
1. This must be glaringly obvious, but how do I use django to load my
homepage (index.html in the public_html root)? I understand about
views and url matching, but there is no views.py in the main directory
and I am not sure if I am supposed to create one or not. In other
words, how does django know where to find the page to load when a
visitor simply goes to mysite.com, instead of
mysite.com/something_to_match?
2. The project I am working on has a few tables: media, articles, and
authors. An article can have one author and one or more rows in the
media table associated with it. I currently have an app called
"tables", in which I plan to define the three tables in models.py (I
am only working with authors as a test). All my views, urls, and so
forth will be inside this tables app. Is this generally recommended,
or should I have an app for each table? The tutorial has two tables
defined, but the urls are all /polls/[something], whereas my urls
might be /authors/, /author/[id], /article/[id], and so on (not
sharing /[app_name]/... like the tutorial does). I hope that made
sense!
Normally you would build a dynamic home page but here is a simple
sequence ...
1. Write a hello world index.html which will be your "home" page
2. Put it in <project>/templates where <project> is the directory
containing settings.py
3. In urls.py where your other patterns exist scroll to the end and add
this ...
# note the += which appends this pattern to the others.
urlpatterns += patterns('',
# empty string r'' matches any URL so put it last
(r'', 'flatviews.flatpage'),
)
4. Create a new file flatviews.py in the <project> directory like this ...
from django.shortcuts import render_to_response
def flatpage(request, pagename='index.html'):
return render_to_response(pagename)
Should do the trick. Your mission is now to build your home page from
inherited templates and database content via the django template language.
>
> 2. The project I am working on has a few tables: media, articles, and
> authors. An article can have one author and one or more rows in the
> media table associated with it. I currently have an app called
> "tables", in which I plan to define the three tables in models.py (I
> am only working with authors as a test). All my views, urls, and so
> forth will be inside this tables app. Is this generally recommended,
> or should I have an app for each table?
The layout principle as set down by James Bennet in Practical Django
Projects is to keep it simple. In other words you would begin by keeping
it all in a single app directory.
If it starts to get complex you can refactor into separate directories
eg all views in a views directory etc. In there you can have different
files for different groups of views which might have some similarity
such as all needing to import the same particular model or models.
Models too can be split into different files in a separate models
directory. Keep stuff together which belongs together.
Finally, he says to try and segregate your own project into separate
apps in their own directories with their own urls, models, views etc on
the basis of some sort of standalone functionality.
My own take on this is to not worry when you are a beginner because it
will become obvious when things are getting messy and you suddenly
realise all you have to do is unclutter directories into a nice and
comfortable hierarchy.
One example above is flatviews.py which I said to put in the <project>
directory. If you decided that was getting too cluttered you could make
a views directory and move it into <project>/views/flatviews.py and
refactor urls.py so it called 'views.flatviews.flatpage'
Good luck
Mike
1. I did plan to have a dynamic homepage; its most complex section
will be to display the most recent ten additions to the articles
table. It sounds like I can just create a views directory inside my
site directory and use that. I was hesitant to do this simply because
django didn't create one, and it seems to create what I should use.
That is, if it didn't give me a views folder, I figured there was some
other way to do it than to use a views folder.
2. I will keep my app directory structure for now and modify as necessary.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.