Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Static files dont work on pythonanywhere, even though i set them up correctly and use collectstatic

Hello... so, its been so annoying please help..

I created new django site on pythonanywhere.com but admin site loads without style.

I put these settings in settings.py file:

STATIC_URL = '/static/'

STATIC_ROOT ='static'

I used python manage.py collectstatic command and it created new admin folder (with css, js etc.) int my static folder.

BUT ADMIN SITE IS STILL WITHOUT STYLES. WHAT IS THIS

please help

p.s. im using virutalenv created with virtualwrapper

p.s.s. its working if i put /static/ folder into Static Files on pythonanywhere.com web panel. But tutorials said thats its a bad way to do this. HELP

/r/djangolearning
https://redd.it/87zfl4
Submit flask application to PyPi

I would like to submit my flask application to PyPi, so that other users will be able to use the application themselves. I know how to write a setup.py file. But I'd like to know how the user would start the server. Should I create an entry point or is there a better solution for that?

/r/flask
https://redd.it/8810jg
Can I use Jupyterhub with ipyleaflet

I have Hadoop / Spark infrastructure on an isolated (from www) cluster. The edge node should run a Jupyterhub server where users can start notebooks from. Is it easily possible for the user (within his frontend / browser) to use ipyleaflet or other map tools or do I have to grant the server access to the www?

/r/IPython
https://redd.it/87zifl
[P] Leela Chess Zero: The fork of Leela Zero for chess, an open-source distributed effort to reproduce Deepmind's AlphaZero.

I think most of the people here followed Deepmind's AlphaGo, then AlphaGoZero and finally AlphaZero's achievements. However Google did not release the weights for all thoses networks, so a community has formed trying to reproduce and maybe improve the AlphaZero engine.

To do this, a distributed effort to play self-play games has started, and the training is done on a single powerful computer (It can update the weights in about 5 hours currently).

You can see the self-play ELO curve (not representative of real ELO) on the [website](http://lczero.org/).

If you want to help the project by sharing your GPU/CPU, think about following the instructions on the "Getting Started" section of the website.

As of now, it would take about 400 days to reach the 44.000.000 games played by Deepmind, but that could change thanks to you!

Some useful links to learn more and talk about the project:

* Try playing her yourself! (all calculations done server-side): http://play.lczero.org/
* Website: http://lczero.org
* Getting started: https://github.com/glinscott/leela-chess/wiki/Getting-Started
* GitHub: https://github.com/glinscott/leela-chess/
* Discord: https://discord.gg/pKujYxD
* Forum: https://groups.google.com/forum/#!forum/lczero

Also for some fancy stats here is her learning to castle:
https://i.imgur.com/J8t7bf4.png

Her learning not to move the king early (not including castling):
https://i.imgur.com/aWqOsNg.png

Some piece movements from one of the latests gen: https://i.imgur.com/C5SAZs6.png

Other stats (such as openings) can be found here: https://github.com/glinscott/leela-chess/issues/166

/r/MachineLearning
https://redd.it/88035j
A great course for not only beginners but for people who'd like to do a quick Django refresher. Even I'm working with Django for a while already, I learned one or two new hints that will help me to improve my code in the future.
http://www.certifiedonlinecourses.website/the-ultimate-beginners-guide-to-django-python-web-dev-website

/r/django
https://redd.it/88515h
Copy and turn django_filters context into geojson

I am working on a page where I have django_filters and a django_table2 table rendered. I want to copy the filtered context into a geojson so that I can load a leaflet map in the template that changes when the information is filtered.

I am able to get and print the context data like so:
class FilteredPermitListView(SingleTableMixin, FilterView):
table_class = PermitTable
model = Permit
template_name = 'permit/permit_listview.html'

filterset_class = PermitFilter

def get_context_data(self, **kwargs):
'''
Overriden version of `.TemplateResponseMixin` to inject the table into
the template's context.
'''
context = super(SingleTableMixin, self).get_context_data(**kwargs)
table = self.get_table(**self.get_table_kwargs())
context[self.get_context_table_name(table)] = table
print(context['permit_list'])
return context

Here is a truncated view of my model:

class Permit(models.Model):
abstract = models.CharField(max_length=255, null=True, blank=True)
api_10 = models.CharField(max_length=255, null=True, blank=True)
approved_date = models.DateField(null=True, blank=True)
block = models.CharField(max_length=255, null=True, blank=True)

My plan is to loop through the context data and great geojson to be added to the context but I cant figure out how to loop through the values. If I change this line:

print(context['permit_list'])

Into this line:

print(context['permit_list']['abstract'])

['abstract'] is one of the columns in the permit model. It just gives me an 500 error.

I think I need to get something from the queryset in the context but I'm lost. Does anyone know what I'm doing wrong?

/r/django
https://redd.it/884tdh
Help needed getting a distinct ordered queryset from two tables..

I'm trying to get an ordered queryset (or just values_list) from Django ORM but having trouble getting the right results. I am using Mysql, so I can't use distinct('price'). The following SQL is working:

SELECT DISTINCT p.price_category_id FROM shop_price AS p
JOIN shop_stock AS s ON p.product_id = s.product_id
WHERE p.product_id = 123
AND p.price_category_id = s.price_category_id
AND s.sold_out = False
ORDER BY p.price DESC


/r/django
https://redd.it/881xd9
Permission: All new users have permissions to everything. Why? [2.0]

First off: I'm new to webdev, and learning Django for funsies. I've been programming for about 2 years.

I have a group, 'employee' that has add/edit/delete permission on model 'tour'.

However, you can add/edit/delete tours without being in the 'employee' group.

This is a pretty barebones project, and I just started adding auth stuff (using basic vanilla Django-official-documentation-2.0 auth features).

I know how to remove permissions, but I feel like I'm missing a piece of information bigger than that.

Why are all users defaulting to have these permissions? What's the point of adding permissions to groups when they've already had them on default?



[**Solved!**](https://www.reddit.com/r/django/comments/881rl2/permission_all_new_users_have_permissions_to/dwh7ktd/) I'm a dummy.
> The admin checks the permissions automatically but in Your own views You have to check the permission explicitly. /u/old_faraon

/r/django
https://redd.it/881rl2
How To Create a Flask RESTful API with Unittest Without A Database?

Hello guys,

I'm wondering, is there a way to create a Flask API and write a unittest for GET, POST, DELETE and PUT without integrating a database and instead test them out using classes? All the examples/tutorials I'm finding they're all using a database like Postgres, Mong DB etc...

I'm completely new to this concept as I have never created a web app or anything similar. I just know the basics of Python and that's about it. So, how can I write a Flask app in a TDD way without utilizing a database? This is all for a test project assignment I have been given.

/r/flask
https://redd.it/888lbu
Adding commenting capabilities to Wagtail 2, any suggestions?

Hi All, am working on a new blog site in Wagtail, and i wanted to make sure it had a moderated commenting feature. I was wondering if that's baked into Wagtail, or as an app (haven't found any yet).

I've used [isso](https://posativ.org/isso/) before, and that's been solid, but i'm curious if any well-done integrations already exist that you have used or know about.

Thank you,
m


/r/django
https://redd.it/88b2qk
[D] Preventing Triplet networks from collapse

What are your strategies for preventing collapse in triplet networks \(for metric learning tasks\)?

Things that I have tried:

* Semi\-hard negative mining.
* Hard negative mining, with progressively increasing batch size \(so the network doesn't see too hard of a loss too early\).
* Distance weighted negative mining \(from the \[Sampling Matters in Deep Embedding Learning\]\([https://arxiv.org/abs/1706.07567](https://arxiv.org/abs/1706.07567)\) paper\).

Anything else that comes to mind? Any strategies that you have used \(either sampling, or otherwise\) to prevent collapse?

/r/MachineLearning
https://redd.it/88by8i
How to dynamically show/hide a fieldset in django admin?

Please excuse me if this is an obvious question but I've been going around in circles on this. I wish to expand a fieldset only if a certain boolean field is True and am not sure how to achieve this in admin.py. Here is a simple example:

# models.py
class MyModel(models.Model):
field1 = models.CharField(max_length=45)
field2 = models.CharField(max_length=45)
field3 = models.CharField(max_length=45)
field4 = models.CharField(max_length=45)
reality_check = models.BooleanField(default=False)

#admin.py
class MyModelAdmin(admin.ModelAdmin):

XXXX = "collapse"
if obj.reality_check == True: # <<-- How do I achieve this ?
XXXX = "open"

fieldsets = (
('Set 1', {'fields':('field1', 'field2', 'reality_check',)}),
('Set 2', {'classes': (XXXX, ), 'fields':('field3', 'field4',)}),
)

/r/django
https://redd.it/88d5hz
Possible to have *inline* interactive plots in Jupyterlab?

Hi, just started with Jupyterlab and it's great but I had a quick question. Is it possible to have interactive plots in Jupyterlab (e.g., a 3D scatterplot made in Matplotlib that you can can rotate in, zoom, etc.) be inline, rather than open in a new window? Not a huge deal if not, just curious.

/r/IPython
https://redd.it/88dtto
Using Ajax to send form data to Django view

I want to use selected value from the template to filter data in months but keep getting 403 (Forbidden) error. Here are my files:

Models.py
class FuelOperation(models.Model):
date = models.DateField(default=datetime.date.today)
liter = models.IntegerField()

Template.html

<form id="month-form" method="post">
{% csrf_token %}
<select id="month-select" class="selectpicker">
<option value="03" name="March">3</option>
<option value="04" name="April">4</option>
</select>
</form>


Javascript

$("#month-select").on("change", function(){
var selectedValue = $(this).text();

$.ajax({
url : "{% url 'index' %}",
type : "POST",
data : {"value" : selectedValue},
dataType : "json",
success : function(){

}
});
});


views.py

def index(request):
if request.method == 'POST':
key = request.POST.get('value')
operations = FuelOperation.objects.filter(date__month=key)
context = {'operations': operations}
return HttpResponse(simplejson.dumps({"success": "true"}, mimetype="application/json"))

return render(request, 'fuel/index.html', context)

urls.py

path('', views.index, name='index'),



And I hope my code formatting appears good because it's my first
time posting so...

/r/django
https://redd.it/88f107
[AF] Flak web app to find amenities (like toilets) near you?

I am learning Flask. So I want to build a web app that will allow users find amenities (like toilets) near you! It will show toilets within walking distance. User can then use Maps to find walking directions to the amenity.

What tech stack will you use to design and build this web app?

Please recommend me some tutorials.


/r/flask
https://redd.it/88bhc1