Django Ошибка NoReverseMatch без аргументов не найдена. 1 шаблон (ов) пробовал - PullRequest
0 голосов
/ 29 апреля 2020

Полная ошибка

Error Message Screenshot showing

У меня есть модель с двумя внешними ключами, как показано ниже

class BatPerformance(models.Model):

    country = models.ForeignKey('TeamStructure', on_delete=models.CASCADE, null=True,  related_name='country')
    player = models.ForeignKey('PlayerStructure', on_delete=models.CASCADE, related_name = 'playerbatperf')

    # Batting Performance Fields
    batting_Matches = models.IntegerField(default=0)
    batting_innings = models.IntegerField(default=0)
    batting_notouts = models.IntegerField(default=0)
    batting_Runs = models.IntegerField(default=0)
    batting_HS = models.IntegerField(default=0)
    batting_avg = models.FloatField(default=0.0)
    batting_ballsfaced = models.IntegerField(default=0)
    batting_strikerate = models.FloatField(default=0)
    batting_hundreds = models.IntegerField(default=0)
    batting_fifty = models.IntegerField(default=0)
    batting_twohundreds = models.IntegerField(default=0)
    batting_fours = models.IntegerField(default=0)
    batting_sixes = models.IntegerField(default=0)

    def __str__(self):
        return str(self.player) + ': ' + str(self.match)

Я создал форму за то же самое со всеми полями. my views.py как показано ниже.

class BatStatistics(FormView):
    template_name = 'form.html'
    form_class = NewPlayerBatStatistics
    success_url = '.'

    def form_valid(self, form):
        # Form is Valid
        new_team = form.save(commit=True)
        return HttpResponseRedirect(self.get_success_url())

    def form_invalid(self, form):
        # Form is Invalid
        print(form.errors)
        return self.render_to_response(self.get_context_data(form=form))

urls.py

urlpatterns = [
    path('', test),
    path('homepage/', Index.as_view(), name = 'index'),
    path('teamdetails/', Teams.as_view(), name = 'teamlist'),
    path('fixtures/',Fixtures.as_view(), name='fixtures'),
    path('teamdetails/newteam', NewTeam.as_view(), name='newteam'),
    path('teamdetails/<int:pk>/', PlayerDetailView.as_view(), name='teamname'),
    path('teamdetails/newplayers/', NewPlayer.as_view(), name='newplayer'),
    path('teamdetails/<int:player_details_pk>/<int:pk>/', PlayerStatistics.as_view(), name= 'playerdetails'),
    path('teamdetails/<int:player_details_pk>/<int:pk>/batstatistics', BatStatistics.as_view(), name= 'batstatistics'),
    path('teamdetails/<int:player_details_pk>/<int:pk>/bowlstatistics', BowlStatistics.as_view(), name= 'bowlstatistics'),

    ]

В полях формы первые два поля страна и имя игрока. Поэтому, когда я выбираю выпадающий список стран, я не хочу видеть всех игроков стран в выпадающем списке имен игроков. Например: если я выбираю Англию, мне нужно, чтобы в раскрывающемся списке игроков были только игроки Англии.

в соответствии с urls.py

path('teamdetails/', Teams.as_view(), name = 'teamlist'), Дает мне список всех названий команд.

path('teamdetails/<int:pk>/', PlayerDetailView.as_view(), name='teamname'), Дает мне список игроков с первым названием страны и т. д. *

path('teamdetails/<int:player_details_pk>/<int:pk>/', PlayerStatistics.as_view(), name= 'playerdetails') Дает мне детали статистики игроков

path('teamdetails/<int:player_details_pk>/<int:PlayerStructure_details_pk>/batstatistics', BatStatistics.as_view(), name= 'batstatistics') Дает мне обновить статистику игрока, который является формой.

Итак, в этой форме я вижу все списки стран и списки игроков в раскрывающемся списке, когда я даю path('teamdetails/batstatistics', который мне не нужен , поэтому я сформировал URL со всеми URL-адресами, связанными с первичными ключами, но я вижу вышеупомянутую ошибку.

Ссылка на URL, указанная при нажатии кнопки в playerdetails. html

{% extends 'base.html' %}
<!DOCTYPE html>
<html>
{% block content %}

<head>
    <meta charset="utf-8"> {% load staticfiles %}
    <link rel="stylesheet" href="{% static 'css/details.css' %}">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="btn pull-right"> 
                <a href="{% url 'batstatistics'  %}" style="height:50px;width:300px;"  class="btn btn-success" role="button" aria-pressed="true">Batting Statistics Update</a>  
                <a href="{% url 'bowlstatistics'  %}" style="height:50px;width:300px;"  class="btn btn-success" role="button" aria-pressed="true">Bowling Statistics Update</a>                
            </div> 
        </div>
        
    </div>
    
    <div>
        <div class="cb-col cb-col-100 cb-bg-white">
            <div class="cb-col cb-col-20 cb-col-rt"><img height="200" width="270" title="profile image" src="{{PlayerStructure_details.imageUri.url}}"></div>
            <div class="cb-col cb-col-80 cb-player-name-wrap">
                <h1 itemprop="name" class="cb-font-40">{{PlayerStructure_details.firstname}} {{PlayerStructure_details.lastname}}</h1>
                <h3 class="cb-font-18 text-gray">{{PlayerStructure_details.country}}</h3></div>
        </div>
        <div class="cb-col cb-col-100 cb-bg-grey">
            <div class="cb-col cb-col-33 text-black">
                <div class="cb-hm-rght">
                    <div class="cb-font-16 text-bold"> Personal Information</div>
                    <div class="cb-col cb-col-40 text-bold cb-lst-itm-sm">Born</div>
                    <div class="cb-col cb-col-60 cb-lst-itm-sm"> {{PlayerStructure_details.BirthDate}} </div>
                    <div class="cb-col cb-col-40 text-bold cb-lst-itm-sm">Birth Place</div>
                    <div class="cb-col cb-col-60 cb-lst-itm-sm"> {{PlayerStructure_details.BirthPlace}} </div>
                    <div class="cb-col cb-col-40 text-bold">Jersey No</div>
                    <div class="cb-col cb-col-60"> {{PlayerStructure_details.JerseyNumber}} </div>
                    <div class="cb-col cb-col-40 text-bold cb-lst-itm-sm">Role</div>
                    <div class="cb-col cb-col-60 cb-lst-itm-sm"> {{PlayerStructure_details.Role}} </div>
                    <div class="cb-col cb-col-40 text-bold cb-lst-itm-sm">Batting Style</div>
                    <div class="cb-col cb-col-60 cb-lst-itm-sm"> {{PlayerStructure_details.BattingStyle}}t </div>
                    <div class="cb-col cb-col-40 text-bold cb-lst-itm-sm">Bowling Style</div>
                    <div class="cb-col cb-col-60 cb-lst-itm-sm"> {{PlayerStructure_details.BowlingStyle}} </div>
                </div>
            </div>
            
            <div class="cb-col cb-col-67 cb-bg-white cb-plyr-rt-col">
                <div class="cb-hm-rght cb-player-bio">
                    <div>
                        {% for players in PlayerStructure_details.playerbatperf.all %}
                        <div class="cb-plyr-tbl">
                            <div class="cb-font-16 text-bold cb-lst-dom">Batting Career Summary</div>
                            <table class="table cb-col-30 cb-plyr-thead">
                                <thead>
                                    <tr class="cb-bg-grey cb-font-12">
                                        <th></th>
                                        <th class="cb-plyr-th text-right" title="Matches Played">M</th>
                                        <th class="text-right" title="No of Innings Batted">Inn</th>
                                        <th class="text-right" title="No of Not Outs">NO</th>
                                        <th class="text-right" title="No of Runs Scored">Runs</th>
                                        <th class="text-right" title="Highest Score">HS</th>
                                        <th class="text-right" title="Batting Average">Avg</th>
                                        <th class="text-right" title="No of Balls Faced">BF</th>
                                        <th class="text-right" title="Batting Strike Rate">SR</th>
                                        <th class="text-right" title="No of 100s Scored">100</th>
                                        <th class="text-right" title="No of 200s Scored">200</th>
                                        <th class="text-right" title="No of 50s Scored">50</th>
                                        <th class="text-right" title="No of fours hit">4s</th>
                                        <th class="text-right" title="No of sixes hit">6s</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="cb-col-8"><strong>ODI</strong></td>
                                        <td class="cb-plyr-tbody text-right">{{players.batting_atches}}</td>
                                        <td class="text-right">{{players.batting_innings}}</td>
                                        <td class="text-right">{{players.batting_notouts}}</td>
                                        <td class="text-right">{{players.batting_Runs}}</td>
                                        <td class="text-right">{{players.batting_HS}}</td>
                                        <td class="text-right">{{players.batting_avg}}</td>
                                        <td class="text-right">{{players.batting_ballsfaced}}</td>
                                        <td class="text-right">{{players.batting_strikerate}}</td>
                                        <td class="text-right">{{players.batting_hundreds}}</td>
                                        <td class="text-right">{{players.batting_fifty}}</td>
                                        <td class="text-right">{{players.batting_twohundreds}}</td>
                                        <td class="text-right">{{players.batting_fours}}</td>
                                        <td class="text-right">{{players.batting_sixes}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                <div>
                    {% for players in PlayerStructure_details.playerbowlperf.all %}
                    <div class="cb-plyr-tbl">
                        <div class="cb-font-16 text-bold cb-lst-dom">Bowling Career Summary</div>

                        <table class="table cb-col-30 cb-plyr-thead">
                            <thead>
                                <tr class="cb-bg-grey cb-font-12">
                                    <th></th>
                                    <th class="cb-plyr-th text-right" title="Matches Played">M</th>
                                    <th class="text-right" title="No of Innings Bowled">Inn</th>
                                    <th class="text-right" title="No of Balls Bowled">B</th>
                                    <th class="text-right" title="No of Runs Conceded">Runs</th>
                                    <th class="text-right" title="Wickets">Wkts</th>
                                    <th class="text-right" title="Best Bowling in Innings">BBI</th>
                                    <th class="text-right" title="Best Bowling in Match">BBM</th>
                                    <th class="text-right" title="Economy">Econ</th>
                                    <th class="text-right" title="Bowling Average">Avg</th>
                                    <th class="text-right" title="Bowling Strike Rate">SR</th>
                                    <th class="text-right" title="Five Wickets in an Innings">5W</th>
                                    <th class="text-right cb-plyr-stump" title="Ten Wickets in an Match">10W</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="cb-col-8"><strong>ODI</strong></td>
                                    <td class="cb-plyr-tbody text-right">{{players.bowl_matches}}</td>
                                    <td class="text-right">{{players.bowl_innings}}</td>
                                    <td class="text-right">{{players.bowl_noofballs}}</td>
                                    <td class="text-right">{{players.bowl_runs}}</td>
                                    <td class="text-right">{{players.bowl_wkts}}</td>
                                    <td class="text-right">{{players.bowl_wickets_lbw}}</td>
                                    <td class="text-right">{{players.bowl_wickets_economy}}</td>
                                    <td class="text-right">{{players.bowl_wickets_stumped}}</td>
                                    <td class="text-right">{{players.bowl_wickets_avgt}}</td>
                                    <td class="text-right">{{players.bowl_wickets_SR}}</td>
                                    <td class="text-right">{{players.bowl_five_wickets}}</td>
                                    <td class="text-right">{{players.bowl_ten_wickets}}</td>
                                </tr>

                            </tbody>
                        </table>
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
    </div>
    </div>
    </div>
    {% endblock %}
</body>

</html>

Надеюсь, это имеет смысл. Спасибо

Обновление:

Просмотр статистики игрока:

class PlayerStatistics(DetailView):
    context_object_name = 'PlayerStructure_details'
    model = models.PlayerStructure
    template_name = 'CricketDetails/playerstatistics_details.html'

Модели

class PlayerStructure(models.Model):
    clubstate =  models.ForeignKey('Clubstate', on_delete=models.CASCADE,  related_name='clubstate')
    country = models.ForeignKey('TeamStructure', on_delete=models.CASCADE, null=True,  related_name='identifier1')
    firstname =  models.CharField(max_length=255)
    lastname  =  models.CharField(max_length=255)
    imageUri =   models.ImageField(upload_to='images/', verbose_name='image')
    JerseyNumber = models.IntegerField()
    BirthPlace = models.CharField(max_length=10)
    BirthDate = models.CharField(max_length=30)
    Role      = models.CharField(max_length= 20)
    BattingStyle = models.CharField(max_length= 20)
    BowlingStyle = models.CharField(max_length= 20)

    def __str__(self):
        return self.firstname + self.lastname

I вставил html для этого.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...