Fix agent pages URL routing conflict

ISSUE: Agent pages were not opening due to URL pattern conflict between
agent_base/urls.py and individual agent app URLs.

SOLUTION:
- Remove conflicting 'agents/<slug:agent_slug>/' pattern from agent_base URLs
- Add get_absolute_url() method to BaseAgent model for clean URL generation
- Update marketplace template to use agent.get_absolute_url instead of URL reversal
- Remove redundant agent_detail_view that was causing redirect loops

RESULT:
- Individual agent pages now load correctly (/agents/data-analyzer/, etc.)
- Marketplace correctly links to individual agent pages
- Authentication flow works as expected (login required for agent access)
- No more URL conflicts or redirect loops

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude 2025-07-21 20:09:51 +05:30
parent bfdef5b658
commit c645216340
4 changed files with 6 additions and 18 deletions

View File

@ -52,6 +52,10 @@ class BaseAgent(models.Model):
'customer-service': 'from-blue-500 to-blue-600',
}
return gradient_map.get(self.category, 'from-gray-500 to-gray-600')
def get_absolute_url(self):
"""Get the URL for this agent's detail page"""
return f'/agents/{self.slug}/'
class BaseAgentRequest(models.Model):

View File

@ -5,6 +5,5 @@ app_name = 'agent_base'
urlpatterns = [
path('marketplace/', views.marketplace_view, name='marketplace'),
path('agents/<slug:agent_slug>/', views.agent_detail_view, name='agent_detail'),
path('api/agents/', views.agents_api_view, name='agents_api'),
]

View File

@ -29,21 +29,6 @@ def marketplace_view(request):
return render(request, 'agent_base/marketplace.html', context)
def agent_detail_view(request, agent_slug):
"""Agent detail view - redirect to specific agent app"""
try:
agent = BaseAgent.objects.get(slug=agent_slug, is_active=True)
# Redirect to the specific agent app URL
if agent_slug == 'weather-reporter':
return redirect('/agents/weather-reporter/')
else:
# For other agents, redirect to marketplace for now
messages.info(request, f'Agent "{agent.name}" page not yet available.')
return redirect('agent_base:marketplace')
except BaseAgent.DoesNotExist:
messages.error(request, 'Agent not found')
return redirect('agent_base:marketplace')
def agents_api_view(request):
"""API endpoint for agents list"""

View File

@ -91,9 +91,9 @@
<span class="price-text">{{ agent.price }} AED</span>
</div>
{% if user.is_authenticated %}
<a href="{% url 'agent_base:agent_detail' agent.slug %}" class="use-button">Use Now</a>
<a href="{{ agent.get_absolute_url }}" class="use-button">Use Now</a>
{% else %}
<a href="{% url 'authentication:login' %}?next={% url 'agent_base:agent_detail' agent.slug %}" class="use-button">Login to Use</a>
<a href="{% url 'authentication:login' %}?next={{ agent.get_absolute_url }}" class="use-button">Login to Use</a>
{% endif %}
</div>
</div>