On 23 September 2012 06:40, Vincent Fulco <vful...@gmail.com> wrote: > Missing something basic here even after scouring web and running thru online > tut a few times. > > Started a project 'mysite' and added twitter bootstrap then created a static > homepage "index.html' to act as a simple launchpad to other more information > & feature laden pages. Used direct_to_template to access the first page and > it renders fine under the development server and a virtualenv (the latter is > in the path). The homepage has a number of hrefs to the other pages which I > filled in with './foo1', './foo2', etc. > > Using the hello function placed in ~/.../mysite/mysite/views.py, I've tried > to branch off the main page as such in urls.py (goal is /homepage/foo1). > *Note the extra code required in the file isn't represented here. > > from mysite.views import hello > ... > urlpatterns = patterns('', > url(r'^foo1$', hello), > url(r'^foo2$', hello), > url(r'^foo3$', hello), > url(r'^foo4$', hello), > ) > > have also tried: > > urlpatterns = patterns('homepage', > url(r'^foo1$', hello), > url(r'^foo2$', hello), > url(r'^foo3$', hello), > url(r'^foo4$', hello), > ) > > This causes the site to break with a 404 error even though I think I am > supplying a correct regex and a toy function. I suspect there is something > with the mysite views.py not being found but not sure. I have tried to more > explicitly reference the views.py file with mysite.views.py trials.
If you haven't already, enable DEBUG in mysite/settings.py. Your 404 page should then indicate which URL regular expressions it has checked. Are the above URL regular expressions in that list? Is ROOT_URLCONF in mysite/settings.py set to 'mysite.urls'? I just created a toy project with that urls.py and it worked fine. > I am not even sure if philosophically this is considered a good practice of > django. Thanks in advance for your assistance. V. Generally you would not create a views.py in your project directory (mysite/mysite is your project directory). You would usually create an app (mysite/manage.py startapp appname), create your views, app-level URLs, models etc. in there, and then reference them in your project urls.py by including your app's urls.py. Also, generally you would reference the view using a string, instead of the actual view function itself. This saves you from having to import every view, and avoid clashes in larger projects where you may have view functions with the same name in different apps. In the second urls.py you posted, the first parameter to patterns, where you have 'homepage' specified, is used to shorten these view function strings - that parameter is appended to your url definitions, i.e. you could use the following urls.py instead - urlpatterns = patterns('mysite', url(r'^foo1$', 'hello'), url(r'^foo2$', 'hello'), url(r'^foo3$', 'hello'), url(r'^foo4$', 'hello'), ) ... and Django will append 'mysite' to all the view function strings, turning them into 'mysite.hello'. See https://docs.djangoproject.com/en/dev/topics/http/urls/#the-view-prefix > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/ojFywQSzpYsJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.