Nick,

Sorry my other very long posted vanished so I'm going to keep it shorter 
this time.

So I was able to implement what you said. Thanks a lot!

Only tricky part is I had to change my name in the database to "JJZolper" 
instead of "JJ Zolper" so that it could find me.

So now if you do:

http://www.madtrak.com/about/contributors/JJZolper

It works!

However, that's not very practical so I could use some help still. I'm 
wondering if I should come up with some other field in my contributor 
database like "id" or something and see if I could make it so it takes the 
name "JJ Zolper" and creates an id of "jjzolper" and thus when 

http://www.madtrak.com/about/contributors/jjzolper<http://www.madtrak.com/about/contributors/JJZolper>

is called everything is happy because the same code you showed me would go 
through the database and work fine! Is this a good practice or is there a 
better way?

Also, even though I've made progress on requesting the page with the name 
and all that I still have another problem.

On this page:

http://www.madtrak.com/about/contributors

If you click a name to hopefully go to the page of that contributor it 
breaks. Here is the code:

<ol>
{% for Contributor in Contributors_List %}
    <li><a href="{{ Contributor.get_absolute_url }}">{{ Contributor.name 
}}</a><li>
<ul>
<li>Title: {{ Contributor.title }}</li>
</ul>
{% endfor %}
</ol>

So bascially it pulls the contributor name which is messed up now cause I 
changed my name to JJZolper but this seems to work.

I was trying to go after what Melvyn said about permalink and get absolute 
url to try to solve the problem of making these two pages actually connect 
up but I still haven't made it work. Any ideas there?

I could use some help basically depending on the object handling the 
absolute url function and then sending it off to the respective url and 
then the file. I mean those are the right steps I think?

Thanks so much,

JJ

PS. I'm making sure to copy this so hopefully it won't just crap out on me 
before I post it. Oh the joys of spending time on something and it getting 
destroyed. The internet is fun, eh? haha

On Tuesday, August 28, 2012 1:50:09 AM UTC-4, Nick Santos wrote:
>
> Hi JJ,
>
> You're absolutely right that there is a better way to do this that doesn't 
> involve repetition. To start with, check out the docs under example on the 
> page for the URL dispatcher: 
> https://docs.djangoproject.com/en/dev/topics/http/urls/ - I'll walk you 
> through part of it though.
>
> First, let's take a look at how capture groups work. Capture groups allow 
> you to pass a variable portion of the url to a view, which is what you'll 
> need to do in order to have one definition that lets you have a generic 
> view that looks up the contributor. So, you can assign a view to a URL 
> where only part of it is known at the time of the definition, and pass the 
> unknown parts into the view. In your case, your url definition would look 
> like:
>
> urlpatterns = patterns('',
>     .... your other patterns...
>     (r'^about/contributor/(?P<contribname>[a-zA-Z]+)/$', 'your.view.name
> '),
>     ....possibly more patterns ....
> )
>
> So, what that (?P<contribname>[a-zA-Z]+) says, in parts is that we want to 
> capture a value - designated by the parenthesis - to be passed to 
> your.view.name as a named parameter called contribname - this is defined 
> by the ?P<contribname>. That value looks like text with at least one 
> character. The text definition is [a-zA-Z] (careful, this doesn't include 
> spaces right now)and the at least one is +, and comes between two slashes. 
> If you want to learn more about writing things like that, look into regular 
> expressions.
>
> Then, in your view, you can take that parameter and look up the relevant 
> contributor and make the view generic to something like:
>
> def contributor_page(request, contribname):
>     contrib_object = Contributor.objects.filter(name=contribname)
>     return render_to_response('contributor.html', {'Contributor': 
> contrib_object}, context_instance = RequestContext(request))
>
> Then, in outputting your links, you can put the relevant name in the url, 
> etc.
>
> I hope that helps. Let me know if anything is unclear. Good luck
>
>
> On Mon, Aug 27, 2012 at 9:58 PM, JJ Zolper <codin...@gmail.com<javascript:>
> > wrote:
>
>> Hello,
>>
>> I'm trying to develop a simple hyperlink between two pages. It sounds 
>> simple but it's a little bit more complex then that.
>>
>> Here is the template code that proceeds through the database of 
>> contributors:
>>
>> <center><u>Contributors</u></center>
>>
>> <ol>
>>  {% for Contributor in Contributors_List %}
>>     <li><a href="http://www.madtrak.com/about/contributors/";>{{ 
>> Contributor.name }}</a></li>
>>  <ul>
>> <li>Title: {{ Contributor.title }}</li>
>> </ul>
>>  {% endfor %}
>> </ol>
>>
>> and spits out the contributors name in a link form and the title of that 
>> person.
>>
>> My problem is that I want each contributor to have their own separate 
>> page. So if the first guys name for some example is Mike Smith then if you 
>> were to click his name for example you would be sent to 
>> /about/contributor/mikesmith and so on. I supposed I could define a url for 
>> each contributor so I could set this up:
>>
>> <center><u>Contributors</u></center>
>>
>> <ol>
>> {% for Contributor in Contributors_List %}
>>      <li><a href="{{ Contributor.link">{{ Contributor.name }}</a></li>
>> <ul>
>>  <li>Title: {{ Contributor.title }}</li>
>> </ul>
>> {% endfor %}
>>  </ol>
>>
>> but that doesn't seem like the correct way to do this. that 
>> Contributor.link is then hardcoded into the system. It's not generated by 
>> the system obviously.
>>
>> I also have:
>>
>> def mikesmith(request):
>>     mikesmith = Contributor.objects.filter(name='Mike Smith')
>>     return render_to_response('mikesmith.html', 
>> {'Contributor': mikesmith}, context_instance = RequestContext(request))
>>
>> I have that repeated for each and every contributor. This goes againist 
>> Django's DRY mentality so I have a feeling there is a much better way.
>>
>> Thanks,
>>
>>  JJ
>>
>> -- 
>> 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/-/xWx39cCFzvYJ.
>> To post to this group, send email to django...@googlegroups.com<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com <javascript:>.
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/g0V4Hgnej6MJ.
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.

Reply via email to